![Check out Enfold](https://kriesi.at/wp-content/themes/kriesi/images/banner-enfold.jpg)
Tagged: navigation, Portfolio, posts
-
AuthorPosts
-
June 19, 2024 at 1:55 am #1451908
I am trying to program posts and portfolio navigation so they are reversed, locked down to the same category and loop around back to the beginning. I have been able to accomplish the first two, but I can’t get the navigation to loop back to the beginning for either. Any thoughts on what I should add to this code?
/** * previous and next in same portfolio category & reverse */ add_filter( 'avia_post_nav_entries', 'enfold_customization_postnav', 10, 2); function enfold_customization_postnav($entries, $settings) { if($settings['type'] == 'portfolio') { $settings['same_category'] = true; $entries['prev'] = get_previous_post($settings['same_category'], $settings['excluded_terms'], $settings['taxonomy']); $entries['next'] = get_next_post($settings['same_category'], $settings['excluded_terms'], $settings['taxonomy']); } return $entries; } /** * previous and next opposite order posts & reverse */ add_filter( 'avf_post_nav_entries', 'avf_post_nav_entries_mod_reverse', 10, 3); function avf_post_nav_entries_mod_reverse($entries, $settings, $queried_entries) { $settings['same_category'] = true; $entries['prev'] = get_next_post($settings['same_category'], $settings['excluded_terms'], $settings['taxonomy']); $entries['next'] = get_previous_post($settings['same_category'], $settings['excluded_terms'], $settings['taxonomy']); return $entries; }
June 19, 2024 at 5:44 am #1451916Hey jollyrogerd,
Thank you for the inquiry.
Have you tried setting the Enfold > Blog Layout > Single Post Options > Single Post Navigation settings to the third option (Loop post navigation)? Let us know if this works for you.
Best regards,
IsmaelJune 19, 2024 at 7:57 pm #1452032That works without the code, but once I use the above code, that stops working.
June 21, 2024 at 7:34 am #1453488Hi,
Thank you for the update.
What happens if you remove this part of the code that reverses the entries? It might be conflicting with the loop option.
$entries['prev'] = get_next_post($settings['same_category'], $settings['excluded_terms'], $settings['taxonomy']); $entries['next'] = get_previous_post($settings['same_category'], $settings['excluded_terms'], $settings['taxonomy']);
You can then include this code to reverse the order of the loop:
add_filter("avf_post_nav_loop_args", function($args, $settings) { $args["orderby"] = array( 'post_date' => "ASC", 'ID' => "ASC"); return $args; }, 10, 2);
Best regards,
IsmaelJune 25, 2024 at 8:59 pm #1458760Thank you Ismael, I tried that and it broke the containing the loop to one category and still didn’t loop around on the posts.
June 26, 2024 at 7:03 am #1459238Hi,
Thank you for the info.
Please remove all modifications and make sure that the Enfold > Blog Layout > Single Post Options > Single Post Navigation is set to the third option (Loop post navigation). After that, add this code to the functions.php file:
/** * previous and next opposite order posts & reverse */ add_filter( 'avf_post_nav_entries', 'avf_post_nav_entries_mod_reverse', 10, 3); function avf_post_nav_entries_mod_reverse($entries, $settings, $queried_entries) { $settings['same_category'] = true; return $entries; } add_filter("avf_post_nav_loop_args", function($args, $settings) { $args["orderby"] = array( 'post_date' => "ASC", 'ID' => "ASC"); return $args; }, 10, 2);
The filter avia_post_nav_entries filter is no longer necessary.
Best regards,
IsmaelJune 26, 2024 at 11:34 pm #1459795Hi Ismael-
That worked for the looping but it is not locked down to the specific category or reverse the previous and next… in both portfolio categories and post categories. I have added links etc privately.
Thanks
-DanicaJune 27, 2024 at 4:43 am #1459809Hi,
Thank you for following up.
Did you apply multiple categories to the portfolio items? The filter above will not work if the items belong to multiple categories. Please provide an admin account so that we can check the modifications further.
Best regards,
IsmaelJune 27, 2024 at 4:59 am #1459810Hi Ismael-
Yes, some of them do belong to multiple categories.
Login details for you, below (privately)..July 1, 2024 at 5:48 am #1460722Hi,
Sorry for the delay. Looks like it’s not possible to enable looping while the entries are reversed. You may need to disable looping or revert the sorting of the entries to the default.
Best regards,
IsmaelJuly 12, 2024 at 2:31 am #1461886Hi Ismael-
So what do I put if I want it to be locked down to a category, looping within only that category, and default for next and last? This is for both posts and portfolios…
Thanks!July 12, 2024 at 7:00 am #1461894Hi,
We just noticed that this filter is incorrect:
/** * previous and next opposite order posts & reverse */ add_filter( 'avf_post_nav_entries', 'avf_post_nav_entries_mod_reverse', 10, 3); function avf_post_nav_entries_mod_reverse($entries, $settings, $queried_entries) { $settings['same_category'] = true; return $entries; }
To keep the navigation in the same category, you have to replace it with this code instead:
add_filter( 'avf_post_nav_settings', 'avf_post_nav_settings_mod', 10, 1); function avf_post_nav_settings_mod($settings) { $settings['same_category'] = true; return $settings; }
Also, make sure that the posts belong to a single category; having multiple categories will not work.
Best regards,
Ismael -
AuthorPosts
- You must be logged in to reply to this topic.