Tagged: navigation, single post
-
AuthorPosts
-
April 4, 2017 at 10:55 pm #772059
Hi all,
I was looking for a solution to swap the next and previous navigation buttons on a single post. To be clear, if I have a post category with 10 posts and open the category listing page, and then click on the first item (newest post/portfolio entry) in the list. When I view the first item, I will have an arrow on the left to navigate to the next post, which is the newest post after the one I am currently viewing. This is by default. I want the arrow to be on the right.
I searched the forums for a solution and found this: https://kriesi.at/support/topic/blog-post-previous-and-next-arrows/, which is closed to comments. While this solution worked and still works, the thread is old, so it’s a little outdated and there’s a better option in the current version of Enfold (v4.0.5). So I thought I would share it in case it’s useful to someone else out there:
Create a child theme if you haven’t already, and add the following code to the functions.php file in your child theme:
if (!function_exists('swap_single_post_next_and_previous_mod')) { add_filter( 'avia_post_nav_entries', 'swap_single_post_next_and_previous_mod' ); /** * Swap the next and previous navigation on single posts * * @param array $entries * * @return array */ function swap_single_post_next_and_previous_mod( $entries ) { if ( ! isset( $entries['prev'], $entries['next'] ) ) { return $entries; } $temp_prev = $entries['prev']; $entries['prev'] = $entries['next']; $entries['next'] = $temp_prev; return $entries; } }
If you wanted to, you could also pass the
$settings
array to the function via the filter, and then only apply this to certain taxonomies or if certain other conditions are met, e.g.if (!function_exists('swap_single_post_next_and_previous_mod')) { add_filter( 'avia_post_nav_entries', 'swap_single_post_next_and_previous_mod', 10, 2); /** * Swap the next and previous navigation on single posts * * @param array $entries * @param array $settings * * @return array */ function swap_single_post_next_and_previous_mod( $entries, $settings ) { if ( ! isset( $entries['prev'], $entries['next'] ) || $settings['taxonomy'] != 'my-category') { return $entries; } $temp_prev = $entries['prev']; $entries['prev'] = $entries['next']; $entries['next'] = $temp_prev; return $entries; } }
April 6, 2017 at 5:29 pm #773354Hey garethlawson,
Thank you for sharing the knopwledge! :)
Best regards,
Victoria- This reply was modified 7 years, 7 months ago by Victoria.
-
AuthorPosts
- You must be logged in to reply to this topic.