1

Posts are marked in a level 3 category. For example: City (which has the upper categories: State and Country).

- Country
-- State
--- City

I would like the level 2 (State) category to be shown along with respective post, replacing the words PREVIOUS and NEXT in the image.

image Previous/Next post link

Would be like this:

NEW YORK
The previous post title

CALIFORNIA
The next post title

This is the function I have from theme TwentyFourteen:

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;
2
  • Hello! Can you rephrase what you mean by middle category and how it relates to the post? E.g. does the post have CatSon? It's not clear what has what category. Also how do you handle multiple categories on a post? Or did you assign all 3 categories to the post? There's a lot of ambiguity – Tom J Nowell Oct 31 '19 at 18:54
  • Hello @Tom J Nowell I changed the text. Sorry, I am translating from Portuguese to English with Google Translate. I hope you can understand now. – MaryJenny Oct 31 '19 at 19:51

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.