WordPress PHP 中的 if 语句

Cha*_*gor 0 php wordpress

PHP 新手。我的内部 if 语句无法正常工作。它只是呼应“2022”。

<?php

$c = 0;
if ( have_posts() ) :
    while ( have_posts() ) :
        the_post(); 
        
        if (the_time('Y')=="2021") :
            echo "Loop";
            $c++;
        endif;
        
    endwhile;
     
    
endif;
echo "Count = $c"
        
?>
Run Code Online (Sandbox Code Playgroud)

kni*_*ttl 6

the_time输出/回显当前时间;它不会返回它。

显示帖子的撰写时间。

你想要get_the_time的是:

检索帖子的撰写时间。

if (get_the_time('Y') === "2021")
Run Code Online (Sandbox Code Playgroud)