Blacklist category from front page.

Viewing 11 posts - 1 through 11 (of 11 total)
  • #4294
    ambo100
    Participant

    Thanks for creating the theme and sharing it, It’s exactly what I was looking for and I happened to come across it by chance.

    I’d like to be able to blacklist certain categories of posts from appearing on the front page which is currently in the grid layout. Can a feature be implemented to support this or is there a simple workaround?

    #4298
    Daniel Tara
    Keymaster

    In functions.php rewrite the function esplanade_ignore_sticky_posts() like so:

    function esplanade_ignore_sticky_posts( $query ) {
    	global $wp_the_query;
    	if( ( $wp_the_query === $query ) && $query->is_home() && esplanade_get_option( 'slider' ) ) {
    		$query->set( 'ignore_sticky_posts', 1 );
    		$query->set( 'cat', -4 );
    	}
    }

    Replace the number with the ID of the category you wish to exclude.

    • This reply was modified 12 years, 1 month ago by Daniel Tara.
    #4319
    ambo100
    Participant

    Thanks for the quick response. It works perfectly.

    #5117
    Eddy
    Participant

    Just tried this and it crashed the site, had to restore the function.php file. Apparently it conflicted with line 4, which I modified per another thread to keep from repeating the sticky posts on the front page. Any chance I’d be able to do both?

    #5118
    Eddy
    Participant

    Never mind, figured it out. Amazing the havoc an extra bracket can bring! Anyway, is there a way to ignore/block more than one category? I tried using -72, -93, etc, but it would only take the first.

    #5126
    Eddy
    Participant

    This is blacklisting the blocked category not only from the front page, but also from the category page and the back end as well, only accessible by entering the direct URL… I had to undo the changes. Please advise.

    #5147
    Daniel Tara
    Keymaster

    The $query->is_home() conditional assures this doesn’t happen. make sure you have it there.

    #5234
    kri8tiv
    Participant

    hi Daniel,

    the solution you have given is good but sorry to say that it is not so great. I will tell you why, for example I have 100 categories and as the time goes by, the more you post the more categories you will discover to create. If I only wish one category to be displayed on the homepage, it means I have to exclude the other 99 – one by one i have to exclude them, and if there’s new category, i have to go there again to edit the function.php. In other words, for me it’s complicated.

    suggested solution:
    is there a solution that we can make it the other way around? instead of “exclude” reverse it to “include”. in that way, i only need to assign one (1) category to feature on the homepage.

    what do you think?

    #5292
    Daniel Tara
    Keymaster

    If you’re having 100 top-level categories you’re doing a pretty bad job organizing your content. Categories are hierachical so you can make categories children of other categories. Then when you exclude a parent category all the posts assigned to children categories will be ignored as well.

    As for including only a certain category, you have the cat argument which does just that. In fact you can include more than one category.

    #5335
    kri8tiv
    Participant

    I don’t have 100 top-level categories :-), it was just an example to show you that it was complicated to exclude all the other categories if you only want to show one category.

    Can you teach me how to include only a certain category on the homepage besides sticky posts on the slider?

    #5344
    gusandrews
    Participant

    kri8tiv, there are plugins which do a pretty decent job of limiting front-page content to certain categories. I am using PE Category filter (http://pavelespinal.com/resume/downloads/) with Esplanade and it’s working pretty well (though it doesn’t solve my own problem, which is getting posts to appear in three distinct categorized columns).

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.