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

发表评论

电子邮件地址不会被公开。 必填项已用*标注

5 + 6 = ?

网站地图|XML地图

Copyright © 2015-2024 技术拉近你我! All rights reserved.
闽ICP备15015576号-1 版权所有©psz.