Show category from “Next post” and “Previous post” [edited]

Question

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;
0
, , MaryJenny 2 years 2019-10-31T12:28:36-05:00 0 Answers 68 views 0

Leave an answer

Browse
Browse