MEET SITKA | A super-customizable modern WP theme!

Okay
  Print

Have your homepage display a specific post category

By default, the homepage will display your most recent posts from all categories. If you'd like your homepage to only display posts assigned with 1 particular category instead, you can follow these steps:

Navigate to Appearance > Editor > and open up your "functions.php" theme file.
Please be very careful regarding what you add or change within this theme file as it is the "brains" in a way.
Scroll to the bottom of the file and, below the last code within the document, copy & paste the following code:


function my_home_category ($query) {
    if ( $query->is_home() && $query->is_main_query() ) {
    $query->set( 'cat', '6');
    }
}
add_action ('pre_get_posts', 'my_home_category');



Homepage Category Screenshot #1


Within that little bit of code, 3 lines from the top, you'll notice the number value "6". This number represents the category you want to singularly display on your homepage.


Homepage Category Screenshot #2


Whenever you create a category, WordPress assigns it a unique ID number.
To determine your desired category's ID number, check out: How to determine a post, page, or category ID


Within "functions.php", replace the "6" number value with your own category ID's number.
Be sure to save the document when you're finished. Now, your homepage will display just your posts assigned with this particular category!