Viewing 16 posts - 1 through 16 (of 16 total)
  • Author
    Posts
  • #985343

    I’ve read all of the posts about the previous/next arrows on portfolio items not showing only items from the same category but I can’t get them to work. I’m using a child theme and the following in functions.php

    if(!function_exists(‘avia_post_nav’))
    {
    function avia_post_nav($same_category = true, $taxonomy = ‘category’)
    {
    global $wp_version;
    $settings = array();
    $settings[‘same_category’] = $same_category;
    $settings[‘excluded_terms’] = ”;
    $settings[‘wpversion’] = $wp_version;

    //dont display if a fullscreen slider is available since they overlap
    if((class_exists(‘avia_sc_layerslider’) && !empty(avia_sc_layerslider::$slide_count)) ||
    class_exists(‘avia_sc_slider_full’) && !empty(avia_sc_slider_full::$slide_count) ) $settings[‘is_fullwidth’] = true;

    $settings[‘type’] = get_post_type();
    $settings[‘taxonomy’] = ($settings[‘type’] == ‘portfolio’) ? ‘portfolio_entries’ : $taxonomy;

    if(!is_singular() || is_post_type_hierarchical($settings[‘type’])) $settings[‘is_hierarchical’] = true;
    if($settings[‘type’] === ‘topic’ || $settings[‘type’] === ‘reply’) $settings[‘is_bbpress’] = true;

    $settings = apply_filters(‘avia_post_nav_settings’, $settings);
    if(!empty($settings[‘is_bbpress’]) || !empty($settings[‘is_hierarchical’]) || !empty($settings[‘is_fullwidth’])) return;

    if(version_compare($settings[‘wpversion’], ‘3.8’, ‘>=’ ))
    {
    $entries[‘next’] = get_previous_post($settings[‘same_category’], $settings[‘excluded_terms’], $settings[‘taxonomy’]);
    $entries[‘prev’] = get_next_post($settings[‘same_category’], $settings[‘excluded_terms’], $settings[‘taxonomy’]);
    }
    else
    {
    $entries[‘next’] = get_previous_post($settings[‘same_category’]);
    $entries[‘prev’] = get_next_post($settings[‘same_category’]);
    }

    $entries = apply_filters(‘avia_post_nav_entries’, $entries, $settings);
    $output = “”;

    foreach ($entries as $key => $entry)
    {
    if(empty($entry)) continue;
    $the_title = isset($entry->av_custom_title) ? $entry->av_custom_title : avia_backend_truncate(get_the_title($entry->ID),75,” “);
    $link = isset($entry->av_custom_link) ? $entry->av_custom_link : get_permalink($entry->ID);
    $image = isset($entry->av_custom_image) ? $entry->av_custom_image : get_the_post_thumbnail($entry->ID, ‘thumbnail’);

    $tc1 = $tc2 = “”;
    $class = $image ? “with-image” : “without-image”;

    $output .= ““;
    $output .= ” <span class=’label iconfont’ “.av_icon_string($key).”></span>”;
    $output .= ” <span class=’entry-info-wrap’>”;
    $output .= ” <span class=’entry-info’>”;
    $tc1 = ” <span class=’entry-title’>{$the_title}</span>”;
    if($image) $tc2 = ” <span class=’entry-image’>{$image}</span>”;
    $output .= $key == ‘prev’ ? $tc1.$tc2 : $tc2.$tc1;
    $output .= ” </span>”;
    $output .= ” </span>”;
    $output .= “
    “;
    }
    return $output;
    }
    }

    But I’m still getting all portfolio items, not just ones in the same category.

    #985348

    can you please try this instead in your functions.php of your child-theme:

    add_filter( 'avia_post_nav_settings', 'enfold_customization_same_cat' );
    function enfold_customization_same_cat( $s ) {
        $s['same_category'] = true;
      return $s;
    }
    #985353

    No, that doesn’t seem to make any change. I’m still getting arrows to go through all portfolio items. But I also need to reverse the previous/next arrows which is why I’m using the first code snippet.

    #985461

    to have vice-versa post navs you can use this:

    add_filter( 'avia_post_nav_entries', 'enfold_customization_postnav', 10, 2); 
    function enfold_customization_postnav($entries, $settings) {
        $entries['prev'] = get_next_post($settings['same_category']);
        $entries['next'] = get_previous_post($settings['same_category']);
        return $entries;
    }

    and sorry i did not read that it is a portfolio:
    the portfolio “categories” aren’t real categories – they are ( as for events too) taxonomies:

    add_filter('avia_post_nav_settings', 'avia_post_nav_settings_mod');
    function avia_post_nav_settings_mod($settings)
    {
      if(is_singular('portfolio')) {
        $settings['taxonomy'] = 'portfolio_entries';
        $settings['same_category'] = true;}
      return $settings;
    }

    PS: please use for code the code block element on top of the input field:
    click once code – enter your code – click it a second time
    or enter your code – activate the whole code you entered with your mouse – press once code button.
    the code is therefore difficult to read and to check – in addition, certain characters are converted by Boardsoft. The code in the code block can be copied and inserted directly to your functions.php of your child-theme

    • This reply was modified 6 years, 5 months ago by Guenni007.
    #985509

    Hm, no go. When I add just the first snippet, there’s no change. Still getting all portfolio items in the left/right arrows. When I add the second snippet as well, the arrows completely disappeared. If I add just the second one, there are no arrows at all.

    #985542

    hm stange – you see here on Enfold 4.4.1 that portfolio – it has only one other portfolio in the same “category” = frontside
    and you see that there is only that other portfolion in the left right navigation: https://webers-testseite.de/portfolio-item/pirol-hifi/

    #985769

    ok – this seems to be not working anymore on the newest enfold:

    add_filter( 'avia_post_nav_entries', 'enfold_customization_postnav', 10, 2); 
    function enfold_customization_postnav($entries, $settings) {
        $entries['prev'] = get_next_post($settings['same_category']);
        $entries['next'] = get_previous_post($settings['same_category']);
        return $entries;
    }

    there is something new on Enfold 4.4.1 – so please try:

    add_filter( 'avia_post_nav_entries', 'enfold_customization_postnav', 10, 2); 
    function enfold_customization_postnav($entries, $settings) {
        $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;
    }

    but this works on my 4.4.1 install:

    add_filter('avia_post_nav_settings', 'avia_post_nav_settings_mod');
    function avia_post_nav_settings_mod($settings)
    {
      if(is_singular('portfolio')) {
        $settings['taxonomy'] = 'portfolio_entries';
        $settings['same_category'] = true;}
      return $settings;
    }
    #986036

    Ok, the snippet to reverse the next/prev buttons works! But still no go on the limiting to the same category. I made a new portfolio item and put it in it’s own category. No other portfolio items with that category at all. And it still shows the next button and just goes through all portfolio items:

    I’m using

    add_filter('avia_post_nav_settings', 'avia_post_nav_settings_mod');
    function avia_post_nav_settings_mod($settings)
    {
      if(is_singular('portfolio')) {
        $settings['taxonomy'] = 'portfolio_entries';
        $settings['same_category'] = true;}
      return $settings;
    }

    The full functions.php is:

    <?php
    	
    add_filter('avf_postgrid_excerpt_length','avia_change_postgrid_excerpt_length', 10, 1);
    function avia_change_postgrid_excerpt_length($length)
    {
       $length = 300;
       return $length;
    }
    
    add_filter('avia_post_nav_settings', 'avia_post_nav_settings_mod');
    function avia_post_nav_settings_mod($settings)
    {
      if(is_singular('portfolio')) {
        $settings['taxonomy'] = 'portfolio_entries';
        $settings['same_category'] = true;}
      return $settings;
    }
    
    add_filter( 'avia_post_nav_entries', 'enfold_customization_postnav', 10, 2); 
    function enfold_customization_postnav($entries, $settings) {
        $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;
    }
    #986083

    Hey!

    Please try this code to limit the next/prev links to the same category/term:

    
    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_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;
    }
    

    I tested it on my website and it worked.

    Regards,
    Peter

    #986138

    So I used that to replace both previous code snippets and it works to reverse the direction correctly but it doesn’t do anything to limit it to one category. So I know it’s working. If I remove it, the post order reverses to the original. But still shows all portfolio items. We’re talking about the arrows to the right and left of the portfolio items that show up on hover, with the thumbnail of the next portfolio item. Class “avia-post-nav” stuff, right?

    #986372

    yes i know – and you can see on may test-page ( https://webers-testseite.de/portfolio-item/pirol-hifi/ ) that the code above works well for my Enfold 4.4.1
    there are a lot of portfolios but- only two with “category” frontside – and only these two are shown.
    i do not know why it works on my installtion (4.4.1) and on your setup not.

    #986532

    Hey!

    I found the culprit – the “Simple Custom Post Order” plugin which runs on your website breaks the get_next_post() and get_previous_post() functions. As soon as I deactivate the plugin the arrows work as intended. I’d suggest to contact the plugin author because both functions are standard wordpress functions and this seems to be a plugin issue.

    Best regards,
    Peter

    #986601

    Whoa! Thanks man. That’s crazy. I’ll figure it out from here. Amazing work!

    #986795

    Hi,

    Great, glad we could help. Please let us know if you should need any further help on the topic or if we can close it.

    Best regards,
    Rikard

    #987078

    We can close it.

    #987279

    Hi,

    Thanks for letting us know. Please open a new thread if you should have any further questions or problems.

    Best regards,
    Rikard

Viewing 16 posts - 1 through 16 (of 16 total)
  • The topic ‘Previous/Next buttons only same category’ is closed to new replies.