1
WordPress根据标签获取文章列表
Posted by 撒得一地 on 2016年5月25日 in wordpress笔记
在对 WordPress 进行二次开发时,有时候需要根据已经添加的标签来获取相应的文章列表。这时候可以使用 WP_Query 来实现这个功能,直接贴代码:
<?php
$tag = ''; //标签名
$args=array(
'tag' => $tag',
'showposts'=>5, //输出的文章数量
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '5篇指定标签文章输出:';
while ($my_query->have_posts()) : $my_query->the_post();
?>
<p>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
</p>
<?php endwhile;} wp_reset_query(); ?>
1 Comment
这个东西不错,多谢分享