这是完整的工作代码。我不是php开发人员,所以可能有一些事情可以而且应该纠正,但它是有效的。
<?php
$args=array(\'orderby\' => \'ID\', \'order\' => \'DESC\');
$year="2005";
foreach (get_categories( $args ) as $cat) :
$post_ids = get_posts(array(
\'posts_per_page\' => 1,
\'tax_query\' => array(
array(
\'taxonomy\' => \'category\',
\'field\' => \'id\',
\'terms\' => $cat,
),
),
\'fields\' => \'ids\',
));
$cat_post_id=$post_ids[array_rand($post_ids)];
$cat_post_publish_year=get_the_date( \'Y\', $cat_post_id);
if($year!==$cat_post_publish_year)
{
?>
<div style="display: block; clear: both; width: 100%; height: 20px; border-top: 1px solid #fff;"></div>
<?php
$year=$cat_post_publish_year; }
?>
<div style="float: left;">
<a href="<?php echo get_category_link($cat->term_id); ?>"><img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" /></a>
<h3><a href="<?php echo get_category_link($cat->term_id); ?>"><?php echo $cat->cat_name; ?></a></h3>
</div>
<?php endforeach; ?>