加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > wordpress > 正文

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

发布时间:2020-12-14 14:31:16 所属栏目:wordpress 来源:网络整理
导读:由站长 通过网络收集整理的代码片段。编程之家小编现在分享给大家,也给大家做个参考。 我们在学习如何建网站时,使用 wordpress 制作网站,往往需要获取当前文章所属分类下所有文章列表,方便网站用户点击。下面给大家介绍一下 WordPress

以下代码由PHP站长网 52php.cn收集自互联网现在PHP站长网小编把它分享给大家,仅供参考

我们在学习如何建网站时,使用 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>

通过以上的代码,我们可以在网站内容页面,调用文章所属当前分类下的所有文章列表。

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读