Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1071584

    Hi there,
    This is regarding old post which is now closed https://kriesi.at/support/topic/enfold-enable-previous-and-next-post-navigation/ as I do not know if it is possible to re open it.
    Mike already had assisted and helped me to show the arrows just for 1 category, as I was hiding them as default. What I want now to do is to add another category and if it works maybe another 2. I am not very familiar with the code and tried to modify it to my new needs.
    I will post more information in the private area with a temporary login.

    Thank you,
    Vasilis

    #1073533

    Hey Vasilis,
    Sorry for the late reply, I changed your function so that it will add a class to two category types:

    add_filter( 'body_class', 'add_category_class' );
    function add_category_class( $classes ) {
        if( is_single() && has_category('Τελευταία νέα') ) $classes[] = 'news-cat';
        if( is_single() && has_category('Συγγραφείς') ) $classes[] = 'writers-cat';
        return $classes;
    }

    But because you want to hide the post nav on all pages except the ones with the classes I had to write another function to add the css. The original css is limited for “if” & “else” statements, where this javascript can handle it better. This means that you can remove the css used before from your Quick CSS, I have disabled it for now, so this function will work.

    function hide_post_nav_css(){
      ?>
      <script>
    (function($) {
        $(document).ready(function(){
          if ($("body").hasClass("news-cat")) { 
            $('.avia-post-nav').css({ 'display': 'block' });
          }
          else if ($("body").hasClass("writers-cat")) { 
            $('.avia-post-nav').css({ 'display': 'block'});
          } else {
            $('.avia-post-nav').css({ 'display': 'none'});
        }
        });
    
    })(jQuery);
    </script>
    <?php
    }
    add_action('wp_footer', 'hide_post_nav_css');
    

    Please be sure to clear your browser cache, and check your posts, also remember that the “post nav” will only show if the category has more posts to show, and the classes above are present.

    Best regards,
    Mike

    #1073805

    Thank you very much Mike,
    I added another category and it looks it works fine

    #1073980

    Hi,
    I took another look and found that I made an error with tring to use “else if” & “else” and the same time, I have now corrected it.
    You should know that the css in the Quick CSS is not in use now, I have removed it so it won’t be confusing.
    In your css function code you were missing a closing bracket, I added it for you, now you can see what code to copy if you want to do it again.
    The function for adding a class was correct
    Unless there is anything else we can assist with on this issue, shall we close this then?

    Best regards,
    Mike

    #1074361

    Hi Mike,
    I just had a look and it does not seem to be working one category. https://aimonas.gr/%CE%B5%CE%BC%CE%BC%CE%B1%CE%BD%CE%BF%CF%85%CE%AE%CE%BB-%CE%B1%CE%BD%CE%B4-%CE%BA%CE%BF%CE%BD%CF%84%CE%BF%CE%B3%CE%B9%CE%AC%CE%BD%CE%BD%CE%B7%CF%82/
    Posting details in private area.

    Thank you!

    #1074392

    Hi,
    I took another look, the class was being added, but the middle if statement was not executing, I thought it was before.
    Anyways I found out that you can’t use “if”, or “else if” that way, it must be “else” like this:

    (function($) {
        $(document).ready(function(){
        if ($("body").hasClass("news-cat")) { 
            $('.avia-post-nav').css({ 'display': 'block' });
          }
    	else ($("body").hasClass("artists-cat")) { 
            $('.avia-post-nav').css({ 'display': 'block'});	 
    	   }	   
    	else ($("body").hasClass("writers-cat")) { 
            $('.avia-post-nav').css({ 'display': 'block'});
    	   }
        else {
            $('.avia-post-nav').css({ 'display': 'none'});
        }
        });
    
    })(jQuery);

    This seems to work now, please check.

    Best regards,
    Mike

    #1074852

    You are a champ Mike!
    Looks like it is working no and you can close it.

    Thank you.

    #1075260

    Hi,
    Glad to hear it’s working and that we were able to help, we will close this now. Thank you for using Enfold.

    For your information, you can take a look at Enfold documentation here
    For any other questions or issues, feel free to start new threads under Enfold sub forum and we will gladly try to help you :)

    Best regards,
    Mike

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Previous and next post navigation – want to add another 2 categories’ is closed to new replies.