首页 论坛 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>

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

版权:言论仅代表个人观点,不代表官方立场。转载请注明出处:https://www.52diyhome.com/forum/65367.html

发表评论
暂无评论
  • 0 +

    访问总数

  • 0 +

    会员总数

  • 0 +

    资源总数

  • 0 +

    今日发布

  • 0 +

    本周发布

  • 0 +

    运行天数

资源在于分享,创作来源想象