下面是编程之家 jb51.cc 通过网络收集整理的代码片段。编程之家小编现在分享给大家,也给大家做个参考。
我们在学习如何建网站时,使用 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>
通过以上的代码,我们可以在网站内容页面,调用文章所属当前分类下的所有文章列表。
以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。