<?php
//包括制定分类使用上面注释下面2行
//$scat = get_categories('include=1,2,3,4');
//获得全部
$scat = get_categories('hide_empty=0');
foreach ($scat as $mx_cat) {
$cat[$mx_cat->cat_ID] = $mx_cat->cat_name;
}
foreach ($cat as $category) {
$category_name = $category;
$category_id = get_cat_ID( $category_name );
$category_link = get_category_link( $category_id );
?>
<div class="cats" id="cats-index">
<h2 class="title">
<a href="<?php echo ($category_link);?>" title="<?php echo ($category_name);?>"><?php echo ($category_name);?></a>
</h2>
<ul>
<?php
$query = new WP_Query();
$query->query('caller_get_posts=1&posts_per_page=8&cat=' . $category_id);
if($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
?>
<li>
<span class="date"><?php the_time('m-d');?></span>
<a href="<?php the_permalink();?>"><?php the_title();?></a>
</li>
<?php endwhile; else: ?>
<li>暂无文章</li>
<?php endif;?>
<?php wp_reset_query();?>
</ul>
</div>
<?php } ?>
WordPress查询分类前几条
最新推荐文章于 2023-02-04 16:54:00 发布