• Resolved operationblessing

    (@operationblessing)


    Is there a way to post new postings to a category, but not have it appear on the front page? I want to have special reports in a special category, but do not want them to appear on the top of the front page, since there will probably be quite a few dealing with a specific topic that I do not want to distract the main page from?

    So, is there a way to separate out posts from appearing on the front page, and have them only appear under their specific assigned category?

Viewing 7 replies - 1 through 7 (of 7 total)
  • There sure is.

    Just below “the loop” (<?php while (have_posts()) : the_post(); ?>) of the index.php of your theme, you put this:

    <?php if (in_category('218')) continue; ?>

    Replace 218 by the number of the category that you want to exclude.

    Thread Starter operationblessing

    (@operationblessing)

    Sweet, thanks, I did it and it seems to work just fine.

    Thread Starter operationblessing

    (@operationblessing)

    OK, the code works, but I am seeing a little issue with it. It excludes the posts from appearing on the front page, but it still counts them as new posts on the page counter. Meaning, our page is set to show 6 posts on the front page, and if we post 5 posts to this category, they do not show on front, but the front page counts them, and thus only shows one post on the front page.

    I remedied this by increasing the number of posts to show, but since there will always be more posted, this will be a hassle to keep up with and monitor. Is there any additional code that will make them not show, and also not be counted?

    I have the same ‘problem’. They also appear among the recent posts, category, tag, archive pages etc. The only thing the code does is tell WP to “continue” when it runs into a post in a certain category on the idex. It’s not really fancy, but it does what you asked initially 🙂

    Thread Starter operationblessing

    (@operationblessing)

    So, does any one know any additional code to fix this issue?

    hi, i carried this out to exclude my videos category from showing up on the front page and it worked a treat. however now instead of my 3 articles showing up on the front page (as was) from my articles category it only shows 1 article with a link below named “older entries” which i need to click to see the rest of the articles/front page content.

    how can i get my articles back on the front page… i have my reading settings configured to show 3 posts on the front page.

    thanks for your help

    You could use a filter to exclude set categories when on the front page.

    <?php
    function front_page_excludes($query) {
    	if($query->is_front_page) {
    		$query->set(
    			'category__not_in',
    			array(1,2)
    		);
    	}
    	return $query;
    }
    add_filter('pre_get_posts', 'front_page_excludes');
    ?>

    1 and 2 are the IDs for the categories to exclude.. adjust them as required (making sure to leave them inside an array).

    Code above would go into your theme’s functions.php

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Exclude posts from showing on front page?’ is closed to new replies.