WordPress.org

Forums

Can I Make specific posts not show on the home page? (4 posts)

  1. livenyca
    Member
    Posted 2 years ago #

    I use a page lines template on wordpress and would like certain posts to only appear in the category section and not on the home page. Is that possible? Thanks

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    see:
    http://codex.wordpress.org/Function_Reference/query_posts
    http://codex.wordpress.org/Function_Reference/WP_Query

    or try it with this in your theme's functions if your home page is not a static front page:

    function my_post_queries( $query ) {
      // not an admin page and is the main query
      if (!is_admin() && $query->is_main_query()){
        if(is_home()){
          $query->set('category__not_in', array(23,66));
        }
      }
    }
    add_action( 'pre_get_posts', 'my_post_queries' );

    Change 23,66 to the category IDs you want to exclude on the home page

  3. livenyca
    Member
    Posted 2 years ago #

    Thanks for following up. I was hoping for a way to select certain posts to be excluded from the home page at will instead of an entire category. Is there anyway to decide before posting something if it will be on the home page or not?

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    Do you know the ids of these posts?

Topic Closed

This topic has been closed to new replies.

About this Topic