Posted By

chrisaiv on 09/13/14


Tagged

wordpress


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tryan326


Wordpress: Show posts from only one category


 / Published in: JavaScript
 

URL: http://premium.wpmudev.org/blog/one-category-wordpress-homepage/

If you’d like to show posts from only one category on your homepage, then it’s easy enough to do.

  1. /**
  2. * Selective posts
  3. *
  4. * http://premium.wpmudev.org/blog/one-category-wordpress-homepage/
  5. */
  6.  
  7. function my_home_category( $query ) {
  8.  
  9. if ( $query->is_home() && $query->is_main_query() ) {
  10.  
  11. //Category 32 is Frontpage
  12. $query->set( 'cat', '32');
  13. }
  14. }
  15. add_action( 'pre_get_posts', 'my_home_category' );

Report this snippet  

You need to login to post a comment.