昨天自己的WordPress博客需要在另外的页面调用一下其他分类的文章,随上网查了查,WordPress调用特定分类目录下的文章的办法,分享给大家。
首先需要获取分类的ID:WordPress后台 -> 文章 -> 分类目录,找到你需要的分类目录,点击打开,就能看到相应的ID了
然后就可以在你需要的地方添加代码了,在需要显示的页面添加下面的代码,分类ID和显示篇数请根据实际需求调整:
→ 点此获取正规游戏试玩赚钱软件~
<ul>
<?php
$args=array(
'cat' => 745, // 分类ID
'posts_per_page' => 10, // 显示篇数
);
query_posts($args);
if(have_posts()) : while (have_posts()) : the_post();
?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; endif; wp_reset_query(); ?>
</ul>
自己根据需要进行相应的调整即可。
暂无评论