WordPress – Change Default Category Displayed

When WordPress has multiple categories example, Finance and Technology, the site by default will open and display both categories. If only Finance is to be displayed by default, a line of code has to be added to the index.php file.  The index.php file’s location can change depending on the theme being used.

Near the top of the index.php file, before the line of code,  which will look similar to:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

 insert the following line:

<?php if (is_front_page()) { query_posts(“cat=3”); } ?>

The number 3 will need to be changed to the categories ID. This can be found under the admin->posts->categories page. Hover the cursor over the category link and in the status bar it will display cat_ID=x. X will be the category ID to substitute into the line of code above.

Leave a Reply

Your email address will not be published. Required fields are marked *

*