Reputation: 3
I'm having some trouble with syntax when excluding a category from the prev/next nav on single posts. I have it working but not fully how I want it to be.
For the next link, it's working 100%: showing the linked post title and an arrow. For the previous link, it's showing a linked arrow but the title is missing. I'm not quite sure where to insert category 7 in the previous post code in order to get it working properly. I've tried a few different spots but i keep breaking the page and getting errors...
This is how I have it now...
<?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'formationpro' ), '7' . '</span> %title' ); ?>
<?php next_post_link( '<div class="nav-next">%link</div>', '%title <span class="meta-nav">' . _x( '→', 'Next post link', 'formationpro' ), '7' . '</span>' ); ?>
... what do i need to do to make the previous_post_link work properly and show the title?
Thanks in advance for your help.
Kellie
Upvotes: 0
Views: 388
Reputation: 4350
The title swapping only works on the second argument of those functions. You have %title
in the argument for excluded_terms
. Try this instead:
$previous_text = '<span class="meta-nav">' . _x( '←', 'Previous post link', 'formationpro' ) .'</span> %title'
$next_text = '%title <span class="meta-nav">' . _x( '→', 'Next post link', 'formationpro' ). '</span>'
previous_post_link( '<div class="nav-previous">%link</div>', $previous_text, 7);
next_post_link( '<div class="nav-next">%link</div>', $next_text, 7);
Or if you prefer to keep them in your format:
<?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'formationpro' ) . '</span> %title', 7 ); ?>
<?php next_post_link( '<div class="nav-next">%link</div>', '%title <span class="meta-nav">' . _x( '→', 'Next post link', 'formationpro' ) . '</span>', 7 ); ?>
Upvotes: 1