• Hi, I’m trying to modify a theme to link to the next/previous post in the same CATEGORY instead of just the next/previous post by date. The theme uses some custom functions and I’m not sure where to modify it. This is what’s on the bottom of the single-post.php page:

    the_post_navigation(array(
                    'next_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Next', 'magazine-elite' ) . '</span> ' .
                        '<span class="screen-reader-text">' . __( 'Next post:', 'magazine-elite' ) . '</span> ' .
                        '<span class="post-title">%title</span>',
                    'prev_text' => '<span class="meta-nav" aria-hidden="true">' . __( 'Previous', 'magazine-elite' ) . '</span> ' .
                        '<span class="screen-reader-text">' . __( 'Previous post:', 'magazine-elite' ) . '</span> ' .
                        '<span class="post-title">%title</span>',
                ));
    
    			// If comments are open or we have at least one comment, load up the comment template.
    			if ( comments_open() || get_comments_number() ) :
    				comments_template();
    			endif;

    This is the corresponding code in the theme functions page:

    function magazine_elite_post_nav_background() {
        if ( ! is_single() ) {
            return;
        }
    
        $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
        $next     = get_adjacent_post( false, '', false );
        $css      = '';
    
        if ( is_attachment() && 'attachment' == $previous->post_type ) {
            return;
        }
    
        if ( $previous &&  has_post_thumbnail( $previous->ID ) ) {
            $prevthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $previous->ID ), 'post-thumbnail' );
            $css .= '
    			.post-navigation .nav-previous { background-image: url(' . esc_url( $prevthumb[0] ) . '); }
    			.post-navigation .nav-previous .post-title, .post-navigation .nav-previous a:hover .post-title, .post-navigation .nav-previous .meta-nav { color: #fff; }
    			.post-navigation .nav-previous a:before { background-color: rgba(0, 0, 0, 0.4); }
    		';
        }
    
        if ( $next && has_post_thumbnail( $next->ID ) ) {
            $nextthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $next->ID ), 'post-thumbnail' );
            $css .= '
    			.post-navigation .nav-next { background-image: url(' . esc_url( $nextthumb[0] ) . '); border-top: 0; }
    			.post-navigation .nav-next .post-title, .post-navigation .nav-next a:hover .post-title, .post-navigation .nav-next .meta-nav { color: #fff; }
    			.post-navigation .nav-next a:before { background-color: rgba(0, 0, 0, 0.4); }
    		';
        }
    
        wp_add_inline_style( 'magazine-elite-style', $css );
    }

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Link to next post in category’ is closed to new replies.