0

假设有第 1 类、第 2 类、第 3 类……等等。我在类别 2 的帖子页面上。我想在内容区域显示上一个和下一个类别名称,即“类别 1”和“类别 3”。

我怎样才能做到这一点?

4

1 回答 1

2

能够想办法。

<?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);?>
于 2013-03-13T17:55:28.017 回答