0

next

In place of the word PREVIOUS and NEXT, I would like to display the level 2 categories of the respective posts.

This is my current code:

function twentyfourteen_post_nav() {
        $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
        $next     = get_adjacent_post( false, '', false );

        if ( ! $next && ! $previous ) {
            return;
        }
        ?>
        <nav class="navigation post-navigation" role="navigation">
        <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentyfourteen' ); ?></h1>
        <div class="nav-links">
            <?php
            if ( is_attachment() ) :
                previous_post_link( '%link', __( '<span class="meta-nav">Published In</span>%title', 'twentyfourteen' ) );
                else :
                    previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'twentyfourteen' ) );
                    next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'twentyfourteen' ) );
                endif;
                ?>
            </div><!-- .nav-links -->
        </nav><!-- .navigation -->
        <?php
    }
endif;
4
  • 1
    What do you mean by "display the level 2"? it's a child of taxonomy or you want display a term before and after your actual term ? – Sam Oct 29 '19 at 14:20
  • It's a child of taxonomy. I have 3 levels of categories: father, son, grandson. I would like the category son to be displayed. – BobGCA Oct 29 '19 at 15:10
  • 1
    Can you edit your question to show the snippet you have that is printing back your current Next/Prev links?? You'll need a combination of get_next_post(), next_post_link(), and a custom query of that Level 2 cat. – ChristopherJones Oct 29 '19 at 19:32
  • The question has been updated with the function twentyfourteen_post_nav() that I'm using. – BobGCA Oct 29 '19 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.