- This topic has 25 replies, 3 voices, and was last updated 4 years, 10 months ago by
Elvin.
-
AuthorPosts
-
April 27, 2021 at 3:08 am #1750515
Daniel
In Display Post Navigation, how do I replace the post titles with “Previous” and “Next”.
I would like to apply this for a particular post category and keep the post titles navigation for the other categories.
Thank you!
April 27, 2021 at 7:01 am #1751022David
StaffCustomer SupportHi there,
try adding this PHP snippet:
add_filter( 'generate_post_navigation_args', function( $args ) { if ( is_single() && ! in_category('your_category_slug') ) { // Display default post navigation if NOT in category $args['previous_format'] = '<div class="nav-previous">' . generate_get_svg_icon( 'arrow-left' ) . '<span class="prev" title="' . esc_attr__( 'Previous', 'generatepress' ) . '">%link</span></div>'; $args['next_format'] = '<div class="nav-next">' . generate_get_svg_icon( 'arrow-right' ) . '<span class="next" title="' . esc_attr__( 'Next', 'generatepress' ) . '">%link</span></div>'; } elseif ( is_single() && in_category('your_category_slug') ) { // Display Next Previous on specifc category $args['previous_format'] = '<div class="nav-previous"><span class="prev" title="' . esc_attr__( 'Previous', 'generatepress' ) . '">Previous</span></div>'; $args['next_format'] = '<div class="nav-next"><span class="next" title="' . esc_attr__( 'Next', 'generatepress' ) . '">Next</span></div>'; } return $args; } );You will see there are two conditions where you need to replace
your_category_slug– that will be the category for where you want to change the label in both instances.April 27, 2021 at 2:05 pm #1751530Daniel
Thanks very much David.
Replacing links with PREVIOUS and NEXT worked for the particular category, however the links don’t work? You click on the link and nothing happens?April 27, 2021 at 7:50 pm #1751828Elvin
StaffCustomer SupportHi there,
Can you link us to a sample page in question? So we could inspect the links for any issues.
April 27, 2021 at 9:23 pm #1751908Daniel
Sure, here is page with NEXT and PREVIOUS links;
https://staging2.reimann.com.au/projects/coomandook-tank-roof-and-msclHere is page with post title links;
https://staging2.reimann.com.au/services/specialty-design-and-fabrication-projectsThanks
April 28, 2021 at 1:26 am #1752317Elvin
StaffCustomer SupportThanks.
I think that’s because the elseif didn’t have the
%linkso there’s no link rendered.Try this:
add_filter( 'generate_post_navigation_args', function( $args ) { $prev_post = get_adjacent_post( true, '', true, 'category' ); $next_post = get_adjacent_post( true, '', false, 'category' ); if ( is_single() && ! in_category('featured') ) { // Display default post navigation if NOT in category $args['previous_format'] = '<div class="nav-previous">' . generate_get_svg_icon( 'arrow-left' ) . '<span class="prev" title="' . esc_attr__( 'Previous', 'generatepress' ) . '">%link</span></div>'; $args['next_format'] = '<div class="nav-next">' . generate_get_svg_icon( 'arrow-right' ) . '<span class="next" title="' . esc_attr__( 'Next', 'generatepress' ) . '">%link</span></div>'; } elseif ( is_single() && in_category('featured') ) { // Display Next Previous on specifc category $args['previous_format'] = '<div class="nav-previous"><span class="prev" title="' . esc_attr__( 'Previous', 'generatepress' ) . '"><a href="'.get_permalink( $prev_post->ID ).'">Previous</a></span></div>'; $args['next_format'] = '<div class="nav-next"><span class="next" title="' . esc_attr__( 'Next', 'generatepress' ) . '"><a href="'.get_permalink( $next_post->ID ).'">Next</a></span></div>'; } return $args; } );Change
featuredto your category slug.April 28, 2021 at 4:45 am #1752729Daniel
Thanks heaps Elvin – I think we are nearly there.
It works great but the only thing is the Next and Previous links are the wrong way around?
When I click on Previous the next post opens up and when I click on Next the previous post opens up?
I use Post types order plugin to order the posts in the archive.
Is there a way for the Next and Previous links to correspond with the archive menu order?
I really appreciate your great help.April 28, 2021 at 6:20 pm #1754327Elvin
StaffCustomer SupportThanks heaps Elvin – I think we are nearly there.
It works great but the only thing is the Next and Previous links are the wrong way around?
When I click on Previous the next post opens up and when I click on Next the previous post opens up?
I use Post types order plugin to order the posts in the archive.
Is there a way for the Next and Previous links to correspond with the archive menu order?
I really appreciate your great help.It looks like as WordPress intended.
“Previous” points to the “older” adjacent post. “Next” points to the “newer” adjacent post.
But if you wish to change that, Swap the values.
Try modifying this:
$prev_post = get_adjacent_post( true, '', true, 'category' ); $next_post = get_adjacent_post( true, '', false, 'category' );into this:
$prev_post = get_adjacent_post( true, '', false, 'category' ); $next_post = get_adjacent_post( true, '', true, 'category' );April 28, 2021 at 6:45 pm #1754357Daniel
Thanks Elvin. It now works correctly for Next/Previous links.
But still wrong way around for post links? Is this able to be changed around as well?April 28, 2021 at 9:30 pm #1754498Elvin
StaffCustomer SupportBut still wrong way around for post links? Is this able to be changed around as well?
I’m not sure what you mean. Is there any specific condition you want the adjacent posts to be?
Like, for example, you only want adjacent posts from the same category?
Let us know.
May 6, 2021 at 3:07 am #1766996Daniel
Hi Elvin sorry for delay I have been away.
Thats right I do want adjacent posts from same category please?
So Previous/Next for one category (which correctly displays in the menu order)
And the post link titles for the other category (incorrectly displaying in the menu in reverse order).For example in the Services category the first 3 posts I have in menu order are;
MSCL fittings
MSCL site welding
Stainless SteelOn bottom of MSCL site welding post the navigation should be;
< MSCL fittings Stainless Steel >Instead it is the other way around;
< Stainless Steel MSCL fittings >May 6, 2021 at 4:18 pm #1768147Elvin
StaffCustomer SupportCan you try adding this filter? so the post stays within its category
add_filter('generate_category_post_navigation','__return_true');May 7, 2021 at 2:17 am #1768573Daniel
Thanks Elvin works great now with navigation staying within same category.
I appreciate your fantastic support.May 9, 2021 at 6:35 pm #1771851Elvin
StaffCustomer SupportNo problem. Glad you got it sorted. 🙂
May 11, 2021 at 8:51 pm #1775143Daniel
Sorry Elvin I have just picked up on an issue.
Website is now live at reimann.com.au
When going to the first project post “Gawler East Link Road Project”, in the bottom post navigation it says “Previous project” which links to the same post.
I need it to say “Next Project” and link to next post in Projects category menu order (not next ID).
Thanks again
Danny -
AuthorPosts
- You must be logged in to reply to this topic.