Viewing 21 posts - 1 through 21 (of 21 total)
  • Author
    Posts
  • #1491033

    Hi there,

    When using the next and previous buttons in a standard post, I’d like the next or previous post to be from the same category.
    I found this filter (in a topic from 2017 …) but that doesn’t work for me:

    add_filter(‘avia_post_nav_categories’, ‘use_same_category_filter’);
    function use_same_category_filter($same_category)
    {
    $same_category = true;
    return $same_category;
    }

    Is there another solution maybe?

    Beste regards,

    Steven

    #1491062

    try first this shorter form – maybe that will work for you.
    (do not know if the old filter is still ther avia_ …)
    there are more complex snippets – but in almost all installations this will work:

    function enfold_customization_postnav($settings){
      $settings['skip_output'] = false;
      $settings['same_category'] = true;
      return $settings;
    }
    add_filter('avf_post_nav_settings','enfold_customization_postnav', 10, 1);

    edit: here is one with more options:

    function my_avf_post_nav_settings( array $settings ){
      if( true === $settings['is_hierarchical'] ){
        $settings['skip_output'] = true;
        return $settings;
      } 
      if( ! in_array( $settings['type'], array( 'post', 'portfolio' ) ) ){
        $settings['skip_output'] = true;
        return $settings;
      }
      $settings['same_category'] = true;
      $settings['is_fullwidth'] = false;
      $settings['skip_output'] = false; 
      return $settings;
    }
    add_filter( 'avf_post_nav_settings', 'my_avf_post_nav_settings', 10, 1 );
    #1491106

    Hi Günter,

    Thank you for your time and effort. Unfortunately, both options don’t work. The only result is that the next/previous buttons disappear.

    Best regards,

    Steven

    #1491107

    btw.: https://github.com/KriesiMedia/enfold-library/blob/master/actions%20and%20filters/Layout/avf_post_nav_settings.php

    with this snippet you do not even need to set the enfold options on post-navigation.
    You can set with that filter even to loop:

    function my_avf_post_nav_settings( array $settings ){
      if( true === $settings['is_hierarchical'] ){
        $settings['skip_output'] = true;
        return $settings;
      } 
      // the post-types inside the array are allowed to have post-navigation
      if( ! in_array( $settings['type'], array( 'post', 'portfolio' ) ) ){ 
        $settings['skip_output'] = true;
        return $settings;
      }
      $settings['loop_post_nav'] = true;
      $settings['same_category'] = true;
      $settings['is_fullwidth'] = false;
      $settings['skip_output'] = false; 
      return $settings;
    }
    add_filter( 'avf_post_nav_settings', 'my_avf_post_nav_settings', 10, 1 );

    btw. if you set this (is_hierarchical) condition to false – then even pages will have post-navigation

    #1491112

    May I see the page in question?

    you are not talking about a custom post type?
    if so include this (f.e.: event or tribe_events ) post-type to the array

    #1491116

    Sure: https://kunst-en-verhalen.rhijnhof.nl/test/
    As you can see the previous button now links to the current page.
    I did the settings in the blog layout as you suggested and to my knowledge these are normal posts …

    #1491129

    and you have another post inside category: oorlogsslachtoffers ?
    i guess not:

    https://kunst-en-verhalen.rhijnhof.nl/category/oorlogsslachtoffers

    what makes me wonder is that if there is only one post inside that category – there should be no post-nav at all.

    you see – here it is working with same category:
    https://kunst-en-verhalen.rhijnhof.nl/pieta/

    #1491130

    btw: where does the p-tag come from : p.ondertitel
    See DOM:

    #1491150

    Hi,

    Thank you for the inquiry.

    Please provide the login details in the private field so we can check this properly. Did you select the Loop post navigation option in Enfold > Blog Layout > Single Post Navigation settings? Looping will not work correctly when same_category is enabled. Try to set the Single Post Navigation to the first option (Enable post navigation).

    Best regards,
    Ismael

    #1491164

    you can see that if there are more than 1 post inside a category – it works:
    https://kunst-en-verhalen.rhijnhof.nl/pieta/

    what makes me wonder is that on your posts with category: oorlogsslachtoffers (only 1) – there should be no post-navigation. ( Do you have in the page title that p-tag ?)
    so maybe Ismael could help you with this inside your installation

    PS : the setting on Enfold > Blog Layout > Single Post Navigation setting is not important if you use the filter from : above

    With the help of this filter, you can even handle post-types differently.

    #1491165

    By the way: What causes some inconsistencies is not the loop – that works – but when a post/portfolio has multiple categories.
    For example, for a post that has category A, this leads to the next post with category A (but now this has also categories B and C, for example). This is where the decision tree opens up – if no more posts with A are found, then B or C will probably be opened.

    you can see it here: https://webers-testseite.de/defined-order/
    This post only has one category: telemedizin – left and right post-navigation leads to only one post with that category.
    But if you open the next one – this now has more than one category – so this post opens different posts etc.

    The same category post-navigation only makes sense if the posts are always assigned to only one category.

    #1491166

    Hi,

    You’re absolutely right. Stupid of me to miss the fact that there have to be multiple posts in the same category. Otherwise, it wouldn’t work…. Well, now it does.

    Regarding the <p> tag: The designer would like to have a year and a short text next to and below the title. That’s why I added the title to the post like so:
    Henri Flu <span class=”jaartal”>1912-1944</span><br><p class=”ondertitel”>Geliefd huisarts en oorlogsslachtoffer</p>
    But I agree it doesn’t look right when hovering over the next/previous buttons.

    Best regards,

    Steven

    #1491187

    a p-tag inside a span-tag ? try another span with a custom class.

    i tested 2 spans – that will lead to different troubles – because the span.entry-image will be placed inside and not besides entry-title

    you can use :
    Henri Flu • <i>1912-1944</i><span class="ondertitel">Geliefd huisarts en oorlogsslachtoffer</span>
    or
    Henri Flu <i><br>1912-1944</i><span class="ondertitel">Geliefd huisarts en oorlogsslachtoffer</span>

    then you can colorise the i by:

    
    #top .avia-post-nav .entry-title > i {
      color: #ff0;
    }
    #top .avia-post-nav .entry-image img {
      width: 100%;
      height: 100%;
    }
    

    #1491190

    Hi,

    Thanks again. I think my solution would be to hide the title tag altogether (Link naar: …) of the buttons.

    
    title="Link naar: Henri Flu <i>1912-1944</i><br><span class="ondertitel">Geliefd huisarts en oorlogsslachtoffer</span>" aria-label="Henri Flu <i>1912-1944</i><br><span class="ondertitel">Geliefd huisarts en oorlogsslachtoffer</span>">
    
    #1491195

    the link comes from enfold itself. You do not need to insert on title input field links.

    #1491203

    Sorry, that I don’t understand. Where do I find this input field?

    #1491208

    sorry that “Link to: ” comes from Enfold – i thought that you had inserted it to the post title

    #1491226

    Morning!

    Please see screenshot of what I did: https://imgur.com/I1fQbKV.
    I assume there’s no way to disable the hover action?

    EDIT: I think I found some kind solution. Instead of adding extra text to the title, I use the manual excerpt field in the single post page. Then let Content Views pick up the excerpt instead of (part) of the content et voila!

    Regards,
    Steven

    • This reply was modified 2 weeks, 2 days ago by steviger.
    #1491228

    you are talking about this extra tooltip?

    remove the title tag from the anchor by:

    function remove_postnav_title_tags(){
    ?>
    <script type="text/javascript">
    (function($) {
    	$(window).on('load', function(){
    		$('a.avia-post-nav').removeAttr('title');
    	});
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer', 'remove_postnav_title_tags');
    #1491229

    That’s exactly what I meant. However as I mentioned earlier, I found another solution. May also be easier for the end user later on.
    Anyway, thanks again for your time and effort.

    Best regards,

    Steven

    #1491268

    Hi,

    Glad to know this has been resolved! Feel free to open another thread should you have more questions.

    Have a nice day.

    Best regards,
    Ismael

Viewing 21 posts - 1 through 21 (of 21 total)
  • The topic ‘Next/Previous Post within same Category’ is closed to new replies.