Wordpress: Show posts from only one category


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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' );

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.