Before you ask please READ THIS

Blog categories - hide posts from blog

I have a few posts with the same category that are being used by a separate plugin on my site, but due to them being a post in the posts section, this is also displaying as a blog post, in addition to the page loading the plugin to display these posts.

I would like to exclude this category from being displayed in the Fatmoon blog page but continue to display it in the plugin they are being used on.

I wanted to add the script below to the functions.php file but this has been overidden to load the fatmoon framework:

function exclude_category($query) {
if ( $query->is_home() ) {
$query->set('cat', '-CATEGORYNAME');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category');

Any ideas where I need to add this script, or if there is a much simpler way to exclude a certain category from the blog posts?

Thanks

Comments

  • Before you ask, the site is in DEV so is locked out to the public but is accessible by password if you need me to send screenshots of anything...
  • AirAir
    Posts: 10,970
    Hello:-)
    chillwiddastill said: I wanted to add the script below to the functions.php file but this has been overidden to load the fatmoon framework:
    How do you know it was overwritten ? Please test it on default WordPress theme, and tell me does it work good for you there.
    FatMoon uses standard blog mechanics so it shouldn't be the problem.

    With kind regards.
  • edited February 2017 Posts: 52
    What I mean by overwritten is that it includes your script for the framework.


    So I want to add the following script to ignore the blog category which is called "Client", which has the ID of 269 (see screenshot here https://cl.ly/0h1S3b2M3H0N/Screen Shot 2017-02-17 at 14.37.09.png)
    
    function exclude_category($query) {
    if ( $query->is_home() ) {
    $query->set('cat', '-269');
    }
    return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');
    

    Even if I add this script to the top of the existing code after the <?php or at the end of the current code, the category still shows up on the blog post sorting list, but it DOES hide the actual posts...so there is no posts showing, but the category does (see here: https://cl.ly/0W0X2A3K0f1N/Screen Shot 2017-02-17 at 14.49.00.png)

    Is there another snippet of code I need to add so it ignores this category from displaying, instead of just the content within this category?

    Thanks
    Post edited by Air on
  • AirAir
    Posts: 10,970
    Now I understand :-)

    Try doing such change:
    go to fatmoon\parts\category-filter.php line ~81 where you have:
    
    		$query_args = array(
    			'hide_empty' => true,
    			'parent'     => 0,
    		);
    
    and change it to
    
    		$query_args = array(
    			'hide_empty' => true,
    			'parent'     => 0,
    			'exclude' => '269'
    		);
    
    Tell me does it solve your case:-)

    With kind regards.
  • This worked perfectly! Thanks so much ;)
  • I have just noticed that the next and previous posts are still showing posts with this category (see screenshot: https://cl.ly/3w0D0C3g330U/Image 2017-02-18 at 7.26.48 am.png)

    This article is one of the posts that has the category ID 269 which I have excluded. Can you please tell me where I add the ID to exclude this here also please?

    Also, on a separate note, is there a way I can edit this area so I can display the main post image thumb of the blog post in between the previous/next article nav and the blog titles? Please see attached mockup: https://cl.ly/0a0w0S0P3s1W/Screen Shot 2017-02-18 at 07.33.28.png

    In the mockup I set this to 245px wide, so any custom script you can advise me would be much appreciated!

    Thanks
  • AirAir
    Posts: 10,970
    chillwiddastill said: This article is one of the posts that has the category ID 269 which I have excluded. Can you please tell me where I add the ID to exclude this here also please?
    Try this:

    Go to fatmoon\advance\utilities\posts.php line ~259
    and change:

    $prev_post = get_previous_post();
    $next_post = get_next_post();
    to:

    $prev_post = get_previous_post(false, '269');
    $next_post = get_next_post(false, '269');

    chillwiddastill said: Also, on a separate note, is there a way I can edit this area so I can display the main post image thumb of the blog post in between the previous/next article nav and the blog titles?
    A bit lower in same file you have HTML where you can add such PHP code where you need it exactly:
    apollo13framework_make_post_image( $id, array( 245, 100 ))

    Hope that helps.

    With kind regards.
  • edited February 2017 Posts: 52
    Thanks for the additional script for hiding this post category, that works perfectly now!

    My php knowledge is very minimal i'm afraid, so as you can imagine, the moment I added:

    apollo13framework_make_post_image( $id, array( 245, 100 ))

    it killed the site!

    Basically I want this to be like the following:
    
     if($is_prev || $is_next){
                    echo '<div class="posts-nav">';
    
                    if($is_prev){
                        $id = $prev_post->ID;
                        echo '<a href="'.get_permalink($id).'" class="item prev">'
                             .'<span><i class="fa fa-long-arrow-left"></i> '.esc_html__( 'Previous article', 'apollo13-framework' ).'</span>'
    
    "PREVIOUS POST IMAGE TO APPEAR HERE"
    
                             .'<span class="title">'.$prev_post->post_title.'</span>'
                             .'</a>';
                    }
                    if($is_next){
                        $id = $next_post->ID;
                        echo '<a href="'.get_permalink($id).'" class="item next">'
                             .'<span>'.esc_html__( 'Next article', 'apollo13-framework' ).' <i class="fa fa-long-arrow-right"></i></span>'
    
    "NEXT POST IMAGE TO APPEAR HERE"
    
                             .'<span class="title">'.$next_post->post_title.'</span>'
                             .'</a>';
                    }
    
                    echo '</div>';
    

    Therefore is there some other script I need to add to support this new line, so it can reference the correct images?

    Thanks in advance
    Post edited by Air on
  • I also should mention that I am very impressed with your response times!! Its not often you can buy a theme and receive lightning fast responses to questions, usually I have to wait days for a reply! Is there some way I can provide feedback for you?
  • AirAir
    Posts: 10,970
    chillwiddastill said: My php knowledge is very minimal i'm afraid, so as you can imagine, the moment I added:

    apollo13framework_make_post_image( $id, array( 245, 100 ))

    it killed the site!
    OK let me extend my answer:-)

    Go to fatmoon\advance\utilities\posts.php line ~267. We have there such code
    
                    if($is_prev){
                        $id = $prev_post->ID;
                        echo '<a href="'.get_permalink($id).'" class="item prev">'
                             .'<span><i class="fa fa-long-arrow-left"></i> '.esc_html__( 'Previous article', 'apollo13-framework' ).'</span>'
                             .'<span class="title">'.$prev_post->post_title.'</span>'
                             .'</a>';
                    }
                    if($is_next){
                        $id = $next_post->ID;
                        echo '<a href="'.get_permalink($id).'" class="item next">'
                             .'<span>'.esc_html__( 'Next article', 'apollo13-framework' ).' <i class="fa fa-long-arrow-right"></i></span>'
                             .'<span class="title">'.$next_post->post_title.'</span>'
                             .'</a>';
                    }
    
    You need to change it to:
    
                    if($is_prev){
                        $id = $prev_post->ID;
                        echo '<a href="'.get_permalink($id).'" class="item prev">'
                             .'<span><i class="fa fa-long-arrow-left"></i> '.esc_html__( 'Previous article', 'apollo13-framework' ).'</span>'
                             .apollo13framework_make_post_image( $id, array( 245, 100 ))
                             .'<span class="title">'.$prev_post->post_title.'</span>'
                             .'</a>';
                    }
                    if($is_next){
                        $id = $next_post->ID;
                        echo '<a href="'.get_permalink($id).'" class="item next">'
                             .'<span>'.esc_html__( 'Next article', 'apollo13-framework' ).' <i class="fa fa-long-arrow-right"></i></span>'
                            .apollo13framework_make_post_image( $id, array( 245, 100 ))
                             .'<span class="title">'.$next_post->post_title.'</span>'
                             .'</a>';
                    }
    
    You can change those numbers in array( 245, 100 ) to your needs.
    You will also have to style your added image, but I suppose it will be easiest task ;-)

    chillwiddastill said: Its not often you can buy a theme and receive lightning fast responses to questions, usually I have to wait days for a reply! Is there some way I can provide feedback for you?
    Glad you feel that way, it is very "heart warming" :-)

    If you will continue to be our client for your next projects then it is best reward for us, as this tells us we do things right ;-)

    With kind regards.
  • a ha!! Perfect, that fixed it. All I was missing was the . at the beginning of the line! haha typical. Thanks for clearing that up! Just need to style it now and play with the array settings to make it look its best

    Thanks again!
  • One final thing I need on this one please. I would like to be able to add a div around the image to make the 2 images for the thumbnails responsive. Can you please tell me what code I need to add to the new code I added, so that I can wrap them in div containers, for styling?


    I tried this on each element for previous and next images, which killed the page, so any help with just the function would be great!
     '<div class="post_pic_nav">'.apollo13framework_make_post_image( $id, array( 245, 100 ))'</div>' 
    I used standard practice div class code, but added the ' ' as I saw this on other styles applied...
  • AirAir
    edited February 2017 Posts: 10,970
    You need to learn some PHP - it will be time saver for you even basics :-)

    You need more "dots" to connect strings
    .'<div class="post_pic_nav">'.apollo13framework_make_post_image( $id, array( 245, 100 )).'</div>'
    Should be fine:-)

    With kind regards.
    Post edited by Air on
  • yes I really do, especially when its always the smallest things missing that cause the issues! Thanks I will give this a try
  • Hi Air, I have a slight issue with this now that I need to resolve, but it is almost there!

    I have added and styled the thumbnail images so they are both responsive, which all works fine. My issue now is when I have a next and previous article next to eachother that contains a short title on one and a long title on the other one, which pushes one of the articles down to a new line to compensate for the text break.

    Here is what I mean: https://cl.ly/440c101d2u3a/Screen Shot 2017-02-23 at 17.05.33.png

    I tried adding a new div to wrap the first and second articles separately within the posts-nav div, which resulted in this: https://cl.ly/2z1h3V172p2k/Screen Shot 2017-02-23 at 17.11.00.png

    The problem is, when I try to apply these div classes in the php file instead of through Firebug on the page, the layout never seems to turn out how I want for the previous post section!

    So I think the easier option on this would be to add a char restriction on the titles instead, so that it only displays the titles on 1 line and ends with an ellipses at the end when there are too many chars, so it looks like this: https://cl.ly/263W1R1u0C3s/Screen Shot 2017-02-23 at 17.16.26.png

    Can you please let me know what I need to add in order to achieve this? Its the same type of thing that is on the descriptions in the blog list, so I imagine its not too much code to add?

    Thanks again

  • AirAir
    Posts: 10,970
    Show me link to post where problem occurs. You can send it by private message if you need(click on my nick, in top-right corner you will find option "Message").

    With kind regards.
  • I've PM'd you
  • AirAir
    Posts: 10,970
    To fix it, add such custom CSS:

    .posts-nav a {
    vertical-align: top;
    }
    No need to thank ;-)

    With kind regards.
  • Perfect thanks!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!