Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #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;
    }
    
    #1451916

    Hey 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,
    Ismael

    #1452032

    That works without the code, but once I use the above code, that stops working.

    #1453488

    Hi,

    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,
    Ismael

    #1458760

    Thank you Ismael, I tried that and it broke the containing the loop to one category and still didn’t loop around on the posts.

    #1459238

    Hi,

    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,
    Ismael

    #1459795

    Hi 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
    -Danica

    #1459809

    Hi,

    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,
    Ismael

    #1459810

    Hi Ismael-
    Yes, some of them do belong to multiple categories.
    Login details for you, below (privately)..

    #1460722

    Hi,

    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,
    Ismael

    #1461886

    Hi 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!

    #1461894

    Hi,

    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

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.