在wordpress中,如何显示上一个和下一个类别名称?

问题描述:

假设有类别1,类别2,类别3 ...等。 而且我在类别2的帖子页面上。我想在内容区域上显示上一个和下一个类别名称,该内容区域将是'类别1'和'类别3'。在wordpress中,如何显示上一个和下一个类别名称?

我该怎么做?

能够搞清楚。

<?php 
      $categories = get_the_category(); 
      $separator = ' '; 
      $output = ''; 
      if($categories){ 
       foreach($categories as $category) { 
        $prev_step .= '<a href="'.get_category_link($category->term_id-1).'" title="' . esc_attr(sprintf(__("View all posts in %s"), $category->name)) . '" class="previous-step">'.get_cat_name($category->term_id-1).'</a>'.$separator; 
        $next_step .= '<a href="'.get_category_link($category->term_id+1).'" title="' . esc_attr(sprintf(__("View all posts in %s"), $category->name)) . '" class="next-step">'.get_cat_name($category->term_id+1).'</a>'.$separator; 
       } 
      } 
      ?> 
     <?php echo trim($prev_step, $separator);?> 
     <?php echo trim($next_step, $separator);?>