• Resolved ipreferpencils

    (@ipreferpencils)


    I’ve been searching the Forums and Codex for a few days trying about a half dozen fixes and I can’t seem to find a solution that works. All of the solutions I’m coming across seem to be 2-8 years old as well.

    GOAL:
    I have posts with multiple categories attached to them.
    I wish to be able to select a category, select a post within that category, then have the prev-next buttons on that post work within the selected category only.

    PROBLEM: No matter what I do the prev/next links go to the next chronological post regardless what category I’m in.

    SOLUTIONS TRIED: Adding “TRUE” to the prev_post_link and nav_post_link parameaters. Using different plugins. Trying to write my own code excluding the categories (sample below.) Toolbox puts prev/nav links are in functions.php file although I have tried all my solutions within the single.php file too.Tried switching back and forth permalinks to /%postname%/ and /%category%/%postname%/

    CURRENT SETUP: WP 3.6, theme based on Automattic Toolbox 1.4, home page static, blog page “drawings” with 14 categories. Permalinks set to /%category%/%postname%/

    WEBSITE: https://www.newenglanddrawings.com/drawings

    CURRENT CODE I’m Trying…

    I’m NOT a programmer by any stretch of the imagination, however after reading the codex on the previous_post_link and next_post_link I thought this solution would work. I have 14 categories, so I apologize if this is long. This is what I have in the functions.php page of my theme….

    function toolbox_content_nav( $nav_id ) {
    	global $wp_query;
    
    	?>
    	<nav id="<?php echo $nav_id; ?>">
    		<h1 class="assistive-text section-heading"><?php _e( 'Post navigation', 'toolbox' ); ?></h1>
    
    	<?php if ( is_single() ) : // navigation links for single posts ?>
    
    	<?php if ( is_page('drawings') ) {
    	previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'toolbox' ) . '</span> Previous Drawing', TRUE );
    	}else if ( in_category('3') ){
    	previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'toolbox' ) . '</span> Previous Drawing', TRUE, '4,5,6,7,8,9,10,13,14,17,18,19' );
    	}else if ( in_category('4') ){
    	previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'toolbox' ) . '</span> Previous Drawing', TRUE, '3,5,6,7,8,9,10,13,14,17,18,19' );
    	}else if ( in_category('5') ){
    	previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'toolbox' ) . '</span> Previous Drawing', TRUE, '3,4,6,7,8,9,10,13,14,17,18,19' );
    	}else if ( in_category('6') ){
    	previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'toolbox' ) . '</span> Previous Drawing', TRUE, '3,4,5,7,8,9,10,13,14,17,18,19' );
    	}else if ( in_category('7') ){
    	previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'toolbox' ) . '</span> Previous Drawing', TRUE, '3,4,5,6,8,9,10,13,14,17,18,19' );
    	}else if ( in_category('8') ){
    	previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'toolbox' ) . '</span> Previous Drawing', TRUE, '3,4,5,6,7,9,10,13,14,17,18,19' );
    		}else if ( in_category('9') ){
    	previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'toolbox' ) . '</span> Previous Drawing', TRUE, '3,4,5,6,7,8,10,13,14,17,18,19' );
    		}else if ( in_category('10') ){
    	previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'toolbox' ) . '</span> Previous Drawing', TRUE, '3,4,5,6,7,8,9,13,14,17,18,19' );
    			}else if ( in_category('13') ){
    	previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'toolbox' ) . '</span> Previous Drawing', TRUE, '3,4,5,6,7,8,9,10,14,17,18,19' );
    	}else if ( in_category('14') ){
    	previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'toolbox' ) . '</span> Previous Drawing', TRUE, '3,4,5,6,7,8,9,10,13,17,18,19' );
    	}else if ( in_category('17') ){
    	previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'toolbox' ) . '</span> Previous Drawing', TRUE, '3,4,5,6,7,8,9,10,13,14,18,19' );
    	}else if ( in_category('18') ){
    	previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'toolbox' ) . '</span> Previous Drawing', TRUE, '3,4,5,6,7,8,9,10,13,14,17,19' );
    	}else if ( in_category('19') ) {
    	previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'toolbox' ) . '</span> Previous Drawing', TRUE, '3,4,5,6,7,8,9,10,13,14,17,18' ); }
    	?>
    
    		<?php if ( is_page('drawings') ) {
    	next_post_link( '<div class="nav-next">%link</div>', 'Next Drawing <span class="meta-nav">' . _x( '→', 'Next post link', 'toolbox' ) . '</span>' );
    	}else if ( in_category('3') ){
    	next_post_link( '<div class="nav-next">%link</div>', 'Next Drawing <span class="meta-nav">' . _x( '→', 'Next post link', 'toolbox' ) . '</span>', TRUE, '4,5,6,7,8,9,10,13,14,17,18,19' );
    	}else if ( in_category('4') ){
    	next_post_link( '<div class="nav-next">%link</div>', 'Next Drawing <span class="meta-nav">' . _x( '→', 'Next post link', 'toolbox' ) . '</span>', TRUE, '3,5,6,7,8,9,10,13,14,17,18,19' );
    	}else if ( in_category('5') ){
    	next_post_link( '<div class="nav-next">%link</div>', 'Next Drawing <span class="meta-nav">' . _x( '→', 'Next post link', 'toolbox' ) . '</span>', TRUE, '3,4,6,7,8,9,10,13,14,17,18,19' );
    	}else if ( in_category('6') ){
    	next_post_link( '<div class="nav-next">%link</div>', 'Next Drawing <span class="meta-nav">' . _x( '→', 'Next post link', 'toolbox' ) . '</span>', TRUE, '3,4,5,7,8,9,10,13,14,17,18,19' );
    	}else if ( in_category('7') ){
    	next_post_link( '<div class="nav-next">%link</div>', 'Next Drawing <span class="meta-nav">' . _x( '→', 'Next post link', 'toolbox' ) . '</span>', TRUE, '3,4,5,6,8,9,10,13,14,17,18,19' );
    	}else if ( in_category('8') ){
    	next_post_link( '<div class="nav-next">%link</div>', 'Next Drawing <span class="meta-nav">' . _x( '→', 'Next post link', 'toolbox' ) . '</span>', TRUE, '3,4,5,6,7,9,10,13,14,17,18,19' );
    		}else if ( in_category('9') ){
    	next_post_link( '<div class="nav-next">%link</div>', 'Next Drawing <span class="meta-nav">' . _x( '→', 'Next post link', 'toolbox' ) . '</span>', TRUE, '3,4,5,6,7,8,10,13,14,17,18,19' );
    		}else if ( in_category('10') ){
    	next_post_link( '<div class="nav-next">%link</div>', 'Next Drawing <span class="meta-nav">' . _x( '→', 'Next post link', 'toolbox' ) . '</span>', TRUE, '3,4,5,6,7,8,9,13,14,17,18,19' );
    			}else if ( in_category('13') ){
    	next_post_link( '<div class="nav-next">%link</div>', 'Next Drawing <span class="meta-nav">' . _x( '→', 'Next post link', 'toolbox' ) . '</span>', TRUE, '3,4,5,6,7,8,9,10,14,17,18,19' );
    	}else if ( in_category('14') ){
    	next_post_link( '<div class="nav-next">%link</div>', 'Next Drawing <span class="meta-nav">' . _x( '→', 'Next post link', 'toolbox' ) . '</span>', TRUE, '3,4,5,6,7,8,9,10,13,17,18,19' );
    	}else if ( in_category('15') ){
    	next_post_link( '<div class="nav-next">%link</div>', 'Next Drawing <span class="meta-nav">' . _x( '→', 'Next post link', 'toolbox' ) . '</span>', TRUE, '3,4,5,6,7,8,9,10,13,14,18,19' );
    	}else if ( in_category('18') ){
    	next_post_link( '<div class="nav-next">%link</div>', 'Next Drawing <span class="meta-nav">' . _x( '→', 'Next post link', 'toolbox' ) . '</span>', TRUE, '3,4,5,6,7,8,9,10,13,14,17,19' );
    	}else if ( in_category('19') ) {
    	next_post_link( '<div class="nav-next">%link</div>', 'Next Drawing <span class="meta-nav">' . _x( '→', 'Next post link', 'toolbox' ) . '</span>', TRUE, '3,4,5,6,7,8,9,10,13,14,17,18' ); }
    	?>
    
    	<?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>
    
    		<?php if ( get_next_posts_link() ) : ?>
    		<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older Drawings', 'toolbox' ) ); ?></div>
    		<?php endif; ?>
    
    		<?php if ( get_previous_posts_link() ) : ?>
    		<div class="nav-next"><?php previous_posts_link( __( 'Newer Drawings <span class="meta-nav">→</span>', 'toolbox' ) ); ?></div>
    		<?php endif; ?>
    
    	<?php endif; ?>
    
    	</nav><!-- #<?php echo $nav_id; ?> -->

    [Moderator Note: Please post code or markup between backticks or use the code button. Or better still – use a pastebin. Your posted code may now have been permanently damaged/corrupted by the forum’s parser.]

    I would appreciate any help.
    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Modern Fix for Styaing in Same Category with Post Nav With Multiple Categories?’ is closed to new replies.