我不相信有is_new_year()
WordPress中的函数,作为is_new_day()
. 我试图为每套帖子只显示一次年份,最好的方法是什么?
我应该在循环中使用PHP手动检查日期,还是有更好的方法?
我不相信有is_new_year()
WordPress中的函数,作为is_new_day()
. 我试图为每套帖子只显示一次年份,最好的方法是什么?
我应该在循环中使用PHP手动检查日期,还是有更好的方法?
您可以创建一个助手函数,该函数每年仅返回一次年份号:
function get_unique_year( $post_id = 0 )
{
static $last = 0;
$post_id || $post_id = get_the_ID();
$year = get_the_time( \'Y\', $post_id );
if ( $year === $last )
return;
$last = $year;
return $last;
}
然后获取您的帖子并使用该助手:$posts = wp_get_recent_posts(); // or any other function returning posts
foreach ( $posts as $post )
if ( $year = get_unique_year( $post->ID ) )
print "Year: $year<br>";
Wordpress为内置的gallery功能输出了一些非常糟糕的代码,这已经被谈论了很多次了。这是负责库输出的核心代码(在/wp-includes/media.php中):function gallery_shortcode($attr) { global $post; static $instance = 0; $instance++; // Allow plugins/themes to override the de