WordPress教程

WordPress获取当前文章所属分类所有文章

阿里云

我们在学习如何建网站时,使用 WordPress 制作网站,往往需要获取当前文章所属分类下所有文章列表,方便网站用户点击。下面给大家介绍一下 WordPress 获取当前文章所属分类所有文章方法:

  1. <ul>
  2. <?php
  3.     $singleurl = get_permalink($post_id);
  4.     $cats = wp_get_post_categories($post->ID);
  5.     if ($cats) {
  6.     $args = array(
  7.     'category__in' => array( $cats[0] ),                   
  8.     'showposts' => 50,
  9.     'caller_get_posts' => 1
  10.      );
  11.      query_posts($args);
  12.      if (have_posts()) :
  13.      while (have_posts()) : the_post(); update_post_caches($posts); ?>
  14.      <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>
  15.      <?php endwhile; else : ?>
  16.      <li> 暂无文章</li>
  17.      <?php endif; wp_reset_query(); } ?>
  18. </ul>
也想出现在这里?联系我们
创客主机

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

WordPress 获取当前文章所属分类所有文章

已有 371 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!