WordPress获取当前文章所属分类所有文章
我们在学习如何建网站时,使用 WordPress 制作网站,往往需要获取当前文章所属分类下所有文章列表,方便网…
我们在学习如何建网站时,使用 WordPress 制作网站,往往需要获取当前文章所属分类下所有文章列表,方便网站用户点击。下面给大家介绍一下 WordPress 获取当前文章所属分类所有文章方法:
- 
<ul> 
- 
<?php
- 
$singleurl = get_permalink($post_id); 
- 
$cats = wp_get_post_categories($post->ID); 
- 
if ($cats) { 
- 
$args = array( 
- 
'category__in' => array( $cats[0] ), 
- 
'showposts' => 50, 
- 
'caller_get_posts' => 1 
- 
); 
- 
query_posts($args); 
- 
if (have_posts()) : 
- 
while (have_posts()) : the_post(); update_post_caches($posts); ?> 
- 
<li<?php if(get_permalink($post_id)==$singleurl){?> class="video-curry"<?php }?>><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> 
- 
<?php endwhile; else : ?> 
- 
<li> 暂无文章</li> 
- 
<?php endif; wp_reset_query(); } ?> 
- 
</ul> 
通过以上的代码,我们可以在网站内容页面,调用文章所属当前分类下的所有文章列表。
类别:WordPress教程、 
		本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。



还没有任何评论,赶紧来占个楼吧!