WordPress获取当前文章所属分类所有文章

下面是编程之家 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)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

相关文章

我想将wordpress的默认接口路由改掉,愿意是默认的带一个 wp...
wordpress自定义分类法之后,我看到链接都自动在后面添加了一...
事情是这样的,我用 get_post_type 函数创建了一个自定义分类...
最近网站莫名其妙的被顶上了,过一个多小时,就注册一个账号...
最近服务器要到期了,就想着把网站转移到另外一台服务器,本...
今天在写wordpress的接口,然后碰到个奇怪的问题,怎么访问都...