- This topic has 7 replies, 3 voices, and was last updated 3 years, 11 months ago by
Ying.
-
AuthorPosts
-
May 11, 2022 at 5:33 am #2216220
Rohith
We want to add Next and Previous buttons in the pagination instead of numbers.
May 11, 2022 at 6:30 am #2216273David
StaffCustomer SupportHi there,
try adding this PHP Snippet to your site:
add_action('wp',function(){ remove_action( 'generate_after_loop', 'generate_do_post_navigation' ); }); add_action( 'generate_after_loop', function() { echo '<div class="paging-navigation">'; posts_nav_link( ' ', '← Previous', 'Next →' ); echo '</div>'; });How to add PHP: https://docs.generatepress.com/article/adding-php/
May 11, 2022 at 11:12 am #2216787Rohith
Added it but whenever we click on Next, it is showing page numbers from second page.
May 11, 2022 at 11:52 am #2216833Ying
StaffCustomer SupportHi Rohith,
I tested on the code on my side and it works well.
Are you using any other custom functions?
Can you try disable all your plugins except GP premium to test?
If you are using a child theme, can you switch to the parent theme to test?
Let me know!
May 11, 2022 at 12:33 pm #2216863Rohith
It’s working now but I want to display Next and Previous as buttons. Can you please help in doing that.
May 11, 2022 at 12:47 pm #2216881Ying
StaffCustomer SupportYou can use CSS to style it, for example:
.paging-navigation a { padding: 5px 10px; background-color: blue; color: white; text-decoration: none; }May 11, 2022 at 2:40 pm #2216978Rohith
1. It worked. I want to remove the underline, how to do that? There’s an underline for the words ‘Next’ and Previous’
2. The Next and Previous are displaying side by side. Is it possible to display one to the left and the other to the right?May 11, 2022 at 3:18 pm #2217003Ying
StaffCustomer Support1. Updated CSS here:https://generatepress.com/forums/topic/next-and-previous-buttons-in-pagination-instead-of-numbers/#post-2216881
2. Solution 1:
You can try this:
.paging-navigation { display: flex; justify-content: space-between; }But it won’t work when there’s only
nextorprevious.Solution 2:
Add this PHP snippet to add class to the links:
add_filter('next_posts_link_attributes', 'posts_link_attributes_next'); add_filter('previous_posts_link_attributes', 'posts_link_attributes_previous'); function posts_link_attributes_next() { return 'class="next-page"'; } function posts_link_attributes_previous() { return 'class="previous-page"'; }Then add this CSS:
.paging-navigation { display: flex; justify-content: space-between; } .paging-navigation >a.next-page { margin-left:auto; } -
AuthorPosts
- You must be logged in to reply to this topic.