Creating a Template for Each Post Category

You don't have to limit yourself to creating a static-page template for your site. You can use specific templates for the categories you've created on your blog (which we talk about in Book III, Chapter 7) and create unique sections for your site, as Lisa did (with an espresso chaser, of course).

Figure 6-4 shows Lisa's design portfolio. Design Portfolio is the name of a category that she created in the WordPress Dashboard. Instead of using a static page for the display of her portfolio, she used a category template to handle the display of all posts made to the Design Portfolio category.

You can create category templates for all categories in your blog simply by creating template files that have filenames that correspond to the category ID numbers, and then uploading those templates to your WordPress themes directory (see Book VI). Here's the logic to creating category templates:

  • A template that has the filename category.php is a catchall for the display of categories.
  • Add a dash and the category ID number to the end of the filename (shown in Table 6-1) to specify a template for an individual category.
  • If you don't have a category.php or category-#.php file, the category display gets defined from the Main Index template (index.php).

Figure 6-4: Lisa's Design Portfolio page, which uses a category template file.

image

Table 6-1 shows three examples ...

Get WordPress® All-in-One For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.