WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Automatically Don't Post on Home Page (5 posts)

  1. jackmcnally
    Member
    Posted 2 years ago #

    Hi,

    I have categories that people will be posting in (I restricted posting to these categories for certain users), and I don't want those posts to show up on the home page. There will be a large amount of posters, so asking them to check a box every time they post may be hard. Is there a way for posts to automatically not show up on the homepage, but show up on the homepage if I tick a box, or post in a certain category?

    Sorry if you don't understand, I don't know how else to say it, let me know if you need more info!

    Thanks heaps,
    Jack

  2. Big Bagel
    Member
    Posted 2 years ago #

    To only include/exclude certain categories on the home page you can use query_posts().

    http://codex.wordpress.org/Function_Reference/query_posts#Exclude_Categories_From_Your_Home_Page

    Something like this before the loop in your theme's index.php file would work (replacing the numbers with the ID's of the categories you want of course):

    <?php
    if ( is_home() ) {
        global $wp_query;
        $args = array_merge( $wp_query->query, array(
            'category__in' => array( 27, 42 )
        ) );
    
        query_posts( $args );
    }
    ?>

    And as always, if you need to edit your theme and aren't doing this already, it's best to use a child theme.

  3. jackmcnally
    Member
    Posted 2 years ago #

    Hi,

    I did so on my index.php , but to no avail. It seems to be what I want to do, but is not working. I'm unsure as to if index.php is the right place to put it, all the index.php file says is <?php // Silence is golden? ?> . I'm using the mystique theme, if that helps.

    Thanks!

  4. Big Bagel
    Member
    Posted 2 years ago #

    Never seen a theme that didn't use index.php at all. Awesome sauce.

    Try home.php instead. It looks like that's where the loop that runs on the home page lives.

  5. jackmcnally
    Member
    Posted 2 years ago #

    No matter! I used a plugin called Exclude Categories from Front Page. It works perfectly! Thanks for all your help!

Topic Closed

This topic has been closed to new replies.

About this Topic