flaga Treść tego wpisu jest dostępna również w języku polskim

The most common purpose for creating and using category-x.php file is to exclude some category from showing on a front page. For example we have category ‘specials’ that can be viewed only after entering category itself but not on the main page.
First we create new file. We copy content of index.php to editor and save it as category-x.php where x is an ID of category ‘specials’. We need to put that file inside folder with theme we use. Then in index.php just bellow <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> we need to add <?php if (in_category('x')) continue; ?>. And that’s all. Any entry from category ‘special’ won’t show up on front page ;).

But we can use that file to change number of posts displayed on a page for one category only.
NOTE! There is a plugin called Custom Query String which enables to vary number of post being displayed on every page (author, archive, category, year, month, day, search, feed, home). However ALL categories will have the same number of post being displayed.
Let’s say we want to have 5 posts only displayed in category ‘extras’ while on other categories pages 10 posts can be seen. Just as I described above we create category-x.php file. In this case we DON’T need to change anything in index.php file. In category-x.php just above <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> we need to add:

<?php if (is_category()) { $posts = query_posts($query_string . '&orderby=date&showposts=5'); } ?>

And done. When we browse through category ‘extras’ on each page we can see 5 posts only.