您现在的位置是:首页 > 网站制作 > WordpressWordpress

wordpress获取当前分类下所有文章列表

杰帅2023-07-16【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>

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

Tags:wordpress教程   分类   文章

很赞哦! ()

文章评论

本站推荐

站点信息

  • 建站时间:2018-10-24
  • 网站程序:帝国CMS7.5
  • 主题模板《今夕何夕》
  • 文章统计1172篇文章
  • 标签管理标签云
  • 统计数据百度统计
  • 微信公众号:扫描二维码,关注我们