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

WordPress显示当前文章同分类下的文章列表

发布时间:2020-05-23 19:45:54 所属栏目:CMS系统 来源:互联网
导读:目前在做模板区的wordpress模板,感觉如果当前文章页面侧栏或下面显示的还是整个网站的最新文章和热门文章在用户体验方面并不是很好,特别是针对网站分类比较多,内容比较杂的网站

因为用户寻找的是相关的文章,不相关的文章是没有多大兴趣看,博客吧认为这样也能提高PVwordpress显示当前文章同分类最新文章列表: 在想要显示的地方添加以下代码: <div class="msgborder" id="phpcode23"> <?php / single page?show current category articles / ?> <?php if ( is_single() ) : global $post; $categories = get_the_category(); foreach ($categories as $category) : ?> <li class="widget widget_recent_entries" id="<?php $category->term_id;?>-posts"> <h2 class="widgettitle"><?php echo $category->name; ?>

    <?php $posts = get_posts('numberposts=5&category='. $category->term_id); foreach($posts as $post) : ?>
  • <a href="<?php the_permalink(); ?>"><?php the_title(); ?>
  • <?php endforeach; ?>
<?php endforeach; endif ; ?> <?php / end show current category articles / ?>

(编辑:安卓应用网)

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

    推荐文章
      热点阅读