Title: Directing posts to different columns
Last modified: September 9, 2016

---

# Directing posts to different columns

 *  Resolved [adieu](https://wordpress.org/support/users/adieu/)
 * (@adieu)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/directing-posts-to-different/)
 * Would it be possible to have some posts appear in one of the sidebars without
   them first appearing in the main content area?
 * I would like to have small news items appear in a sidebar on [my site](http://salishseapilot.com)
   while reserving the main post area to longer destination features.
 * My understanding is that some premium themes allow this by placing posts in different
   columns based on their category.
 * Thanks
    -  This topic was modified 9 years, 9 months ago by [adieu](https://wordpress.org/support/users/adieu/).

Viewing 15 replies - 1 through 15 (of 26 total)

1 [2](https://wordpress.org/support/topic/directing-posts-to-different/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/directing-posts-to-different/page/2/?output_format=md)

 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/directing-posts-to-different/#post-8166446)
 * Hi adieu. If your smaller news item posts all have the same category you could
   use the Hueman Posts widget in the sidebar and define the category there. Then,
   in a child theme functions.php file, add a pre_get_posts() function to exclude
   that category on the home page.
    [https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Exclude_categories_on_your_main_page](https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Exclude_categories_on_your_main_page)
    -  This reply was modified 9 years, 9 months ago by [bdbrown](https://wordpress.org/support/users/bdbrown/).
    -  This reply was modified 9 years, 9 months ago by [bdbrown](https://wordpress.org/support/users/bdbrown/).
 *  Thread Starter [adieu](https://wordpress.org/support/users/adieu/)
 * (@adieu)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/directing-posts-to-different/#post-8169009)
 * Thanks tons, bdbrown.
 * The news posts will have the same category. I will read up on the link you gave
   me.
 * Cheers
 *  Thread Starter [adieu](https://wordpress.org/support/users/adieu/)
 * (@adieu)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/directing-posts-to-different/#post-8176270)
 * Hi bdbrown,
 * It easy enough to use the Hueman Posts widget to define a particular category.
   I have done that already with another category.
 * My problem is translating the code below.
 *     ```
       function exclude_category( $query ) {
           if ( $query->is_home() && $query->is_main_query() ) {
               $query->set( 'cat', '-1,-1347' );
           }
       }
       add_action( 'pre_get_posts', 'exclude_category' );
       ```
   
 * I don’t know how they have determined the category ID numbers 1 and 1347. I must
   be crazy, but have looked everywhere and not found any numbers to identify my
   categories.
    -  This reply was modified 9 years, 9 months ago by [adieu](https://wordpress.org/support/users/adieu/).
 *  Thread Starter [adieu](https://wordpress.org/support/users/adieu/)
 * (@adieu)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/directing-posts-to-different/#post-8176365)
 * Maybe I’ve figured it out. I’ve get back to you either way. :-}
 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/directing-posts-to-different/#post-8176383)
 * If you hover over a category in the category list the ID will show in the URL
   in the status bar at the bottom. Likewise if you edit a category the ID will 
   be in the address bar URL.
 *  Thread Starter [adieu](https://wordpress.org/support/users/adieu/)
 * (@adieu)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/directing-posts-to-different/#post-8176414)
 * If I place this in the functions.php file on [my site](http://salishseapilot.com):
 *     ```
       function exclude_category( $query ) {
           if ( $query->is_home() && $query->is_main_query() ) {
               $query->set( 'cat', '6' );
           }
       }
       add_action( 'pre_get_posts', 'exclude_category' );
       ```
   
 * Then only category ‘6’ posts appear in the main blog. All the other categories
   are excluded, except the last post that is associated with the main photograph.
   It remains. On my site, category ‘6’ is the “Georgia Strait and Sunshine Coast”
   category.
 * The category I would want to exclude is News, which is 16. I have not yet created
   any News posts. If I place
 *     ```
       function exclude_category( $query ) {
           if ( $query->is_home() && $query->is_main_query() ) {
               $query->set( 'cat', '16' );
           }
       }
       add_action( 'pre_get_posts', 'exclude_category' );
       ```
   
 * in functions.php, no posts appear in the main blog, except for the one associated
   with the main photo.
 * Any ideas what I am doing wrong?
 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/directing-posts-to-different/#post-8176452)
 * `$query->set( 'cat', '16' );`
 * That tells the query to include only category 16. Since you don’t have any posts
   in that category, none are displayed. To exclude the category change it to a 
   negative:
 * `$query->set( 'cat', '-16' );`
 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/directing-posts-to-different/#post-8176458)
 * One recommendation I would make is to name your function so you’re sure it will
   be unique. That way you won’t have to worry about conflicts later. Something 
   like “adieu_exclude_category” or “my_exclude_category”. Change it also in the
   add_action.
 * I’m off for the night. Be back in the morning.
    -  This reply was modified 9 years, 9 months ago by [bdbrown](https://wordpress.org/support/users/bdbrown/).
 *  Thread Starter [adieu](https://wordpress.org/support/users/adieu/)
 * (@adieu)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/directing-posts-to-different/#post-8176512)
 * Thanks bdbrown. Feeling a bit foolish that I forgot the negative sign in all 
   my attempts. It was right in front of me.
 * Is this what you mean?
 *     ```
       function my_exclude_category( $query ) {
           if ( $query->is_home() && $query->is_main_query() ) {
               $query->set( 'cat', '-16' );
           }
       }
       add_action( 'pre_get_posts', 'my_exclude_category' );
       ```
   
 * If I exclude posts such as ‘-14’ which is the ‘Puget Sound’ category, all the
   Puget Sound posts will disappear except the last post which is associated with
   the main photo and the excerpt.
 * Is there an easy way to block posts from appearing there as well? If not, maybe
   I could use a reorder plugin to each time shuffle a ‘News’ category post out 
   of the last spot so it does not appear in the main content area, or does so only
   briefly. That make sense?
 * Your help is much appreciated. Have a good night. I am about to do the same.
 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/directing-posts-to-different/#post-8178689)
 * Assuming “last post” means most recent post in Featured Posts? If so, couple 
   of options.
    1. Select a specific category for Featured Posts. Downside here 
   is Featured Posts will now only show one category, and you have to remember to
   put posts in that category for them to be displayed there. or 2. Copy /parts/
   featured.php to your child theme and modify the query parameters to exclude the
   Puget Sound category like you do in pre_get_posts.
 * Lasagna for scallywags looks good…
 *  Thread Starter [adieu](https://wordpress.org/support/users/adieu/)
 * (@adieu)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/directing-posts-to-different/#post-8179793)
 * Yes, last post means most recent…
 * I have six categories that I would like to appear in the featured posts, but 
   maybe I could give them all one such as “cruising” or “featured”, and a second
   category to distinguish them.
 * I like the second option. I copied featured.php to my child theme. I would like
   to exclude all “news” category posts which will be 16 and have them appear in
   the second sidebar.
 * Admit that I am clueless about how to code that.
 * Googling tells me that I can add this to index.php
 *     ```
       if ( is_home() ) {
           query_posts( 'cat=-3' );
       }
       ```
   
 * to exclude posts, but I have copied index.php to my child theme and tried placing
   the code in a couple places. Nothing happened that I could see (using the numbers
   of a couple of my categories).
    -  This reply was modified 9 years, 8 months ago by [adieu](https://wordpress.org/support/users/adieu/).
 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/directing-posts-to-different/#post-8179928)
 * You don’t need to do anything with index.php; you can remove it from your child
   theme.
 * In your child theme copy of /parts/featured.php (it needs to be in the /parts
   subfolder), in the query at the top of the file, change the “cat” argument to
   exclude category 16 :
 *     ```
       $featured = new WP_Query(
           array(
               'no_found_rows'			=> false,
               'update_post_meta_cache'	=> false,
               'update_post_term_cache'	=> false,
               'ignore_sticky_posts'		=> 1,
               'posts_per_page'		=> hu_get_option('featured-posts-count'),
               'cat'				=> ('-16')
       	)
       );
       ```
   
 *  Thread Starter [adieu](https://wordpress.org/support/users/adieu/)
 * (@adieu)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/directing-posts-to-different/#post-8180070)
 * Works perfectly, bdbrown. Thanks. You’re the best.
 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/directing-posts-to-different/#post-8180123)
 * You’re welcome; glad to help.
 *  Thread Starter [adieu](https://wordpress.org/support/users/adieu/)
 * (@adieu)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/directing-posts-to-different/#post-8180186)
 * Hi bdbrown,
 * Not sure if it is what I have been doing or the settings I’ve changed, but now
   on my home page I have two copies of the most recent post.
 * But it only shows it posted once on my dashboard.
 * Any idea about that?

Viewing 15 replies - 1 through 15 (of 26 total)

1 [2](https://wordpress.org/support/topic/directing-posts-to-different/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/directing-posts-to-different/page/2/?output_format=md)

The topic ‘Directing posts to different columns’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/hueman/3.7.27/screenshot.png)
 * Hueman
 * [Support Threads](https://wordpress.org/support/theme/hueman/)
 * [Active Topics](https://wordpress.org/support/theme/hueman/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/hueman/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/hueman/reviews/)

 * 26 replies
 * 2 participants
 * Last reply from: [adieu](https://wordpress.org/support/users/adieu/)
 * Last activity: [9 years, 8 months ago](https://wordpress.org/support/topic/directing-posts-to-different/page/2/#post-8184164)
 * Status: resolved