我要投稿 | 网站地图 WordPress建站学习平台
WordPress教程网
热门标签: wordpress教程 wordpress函数 wordpress WordPress建站 wordpress插件

图文教程

当前位置:首页> 图文教程

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

发布:WordPress教程网   发布时间: 2023-03-03  游览次数:24次

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

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

本文版权归原作者所有,转载请注明原文来源出处, WordPress教程网 感谢您的支持!

本文链接: http://www.wpcn.net/1157.html

WordPress教程网
WordPress教程网
相关内容