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)
the_time输出/回显当前时间;它不会返回它。
显示帖子的撰写时间。
你想要get_the_time的是:
检索帖子的撰写时间。
if (get_the_time('Y') === "2021")
Run Code Online (Sandbox Code Playgroud)