Today I bring you a very short tutorial but it can be very useful for you. We are going to see how to add a link to the next and previous article in each post automatically in Genesis.
The result we are going to get is the following:
Video tutorial
Subscribe to my channel:
To do this we have to add the following code to the functions.php file of our Genesis template:
// Añadir navegación en los posts. add_action( 'genesis_entry_footer', 'genesis_prev_next_post_nav' );
As you can see in the previous image, the anchor text of the links is the title of the post to which it links, we can also change it to a generic text type "Previous post" and "Next post"
To do this, instead of adding the previous code, we add the following:
add_action( 'genesis_after_entry', 'custom_adjacent_entry_nav' ); /** * Display links to previous and next entry. * * @since 2.3.0 * * @return void Return early if not singular or post type doesn't support `genesis-adjacent-entry-nav`. */ function custom_adjacent_entry_nav() { if ( ! is_singular() ) { return; } genesis_markup( array( 'open' => '<div %s>', 'context' => 'adjacent-entry-pagination', ) ); echo '<div class="pagination-previous alignleft">'; previous_post_link( '%link', '« Post Anterior' ); echo '</div>'; echo '<div class="pagination-next alignright">'; next_post_link( '%link', 'Post Siguiente »' ); echo '</div>'; genesis_markup( array( 'close' => '</div>', 'context' => 'adjacent-entry-pagination', ) ); }
The result will be:
I hope it will be useful to you 😉
regards