当前位置:首页>网络教程>WordPress如何获取当前文章所属分类下的所有文章?

WordPress如何获取当前文章所属分类下的所有文章?

使用WordPress搭建网站的时候往往都需要获取当前文章所属分类下所有文章列表,方便网站用户点击,那么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=”https://www.wpzt.net/<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a></li>

<?php endwhile; else : ?>

<li> 暂无文章</li>

<?php endif; wp_reset_query(); } ?>

</ul>

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

给TA打赏
共{{data.count}}人
人已打赏
网络教程

WordPress如何禁用自动保存和禁用文章修订版本?

2022-7-15 17:37:14

网络教程

WordPress文章页面调用相同分类下文章方法

2022-7-15 17:37:34

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索