• I’m building a WP 2.0.4 blog in which some of the category pages need to have very different page logic from others. I need some advice on the best way to implement this.

    As an example, one of my category pages needs to have some intro text, show the latest post in the category, show excerpts of recent posts in that category, and show a listing of posts in a subcategory.

    Another page needs to show intro text, and all the posts by a specific author.

    Another page needs to show intro text, a list of subcategories and a single post from one of the sub-cats.

    I really don’t like the Template Hierarchy’s approach to category-specific templates, since it relies on category ID — I’d much prefer to refer to cats by name, so I can avoid problems if the IDs change (DB migration, category reorganization, etc.)

    I’m considering bypassing WP’s automatic category URL resolution altogether, and using WP Pages and their templates to do this:

    For each category page I need, I’d create a Page. On each display Page, the intro text and page title would come from the Page info — allowing editors to easily change that boilerplate text without diving into the PHP template. The Page would have its own custom template, where I use query_posts() in the category to pull the info I need.

    If I want the pages grouped (e.g. to make the URLs hierarchical instead of flat), I’d make a parent Page, not really meant to be displayed, but to group subpages. To avoid readers getting caught in WP’s auto-category-URL resolution, I could have ‘category.php’ simply redirect to the Page for the category they’re looking for.

    Does this sound like a viable approach, or am I asking for trouble? Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • What Template Displays a Particular Category

    First, you need to know the Template Hierarchy of Category Templates. The Template Hierarchy determines exactly which Template file is used by WordPress when displaying a Category page.

    Suppose the Category ID of the Category in question is 6. WordPress uses the first Template file it finds in your current Theme’s directory from the following listing …

    https://codex.www.ads-software.com/Category_Templates

    Thread Starter vcohen

    (@vcohen)

    Yep, I’m familiar with Category templates, and have been trying to make my design work with them.

    But as I indicated, they really don’t work well for me. I don’t want to refer to categories by number (category-6.php) — it’s too easy for the IDs to change as the blog gets maintained. I have several environments — dev, test, prod — and in the course of reorganizing categories, loading and reloading the DB, etc., the primary keys in the DB can be different from what they originally were. I don’t want to rely on the “magic number” for the News category, I want to use the category named “News”, regardless of its DB ID.

    Second, my categories are such that I can’t really have a default “category.php” — each needs its own intro text and has quite different logic to gather content.

    Pages give me a way to refer to its template by name, not ID. And they generate a nice URL structure if I nest them. Has anyone else taken this approach?

    Has anyone else taken this approach?

    Probably not.
    I always found a combination of Pages and category templates works the best. For me, at least.

    Has anyone else taken this approach?

    I considered it at very great length, but found Pages to be so “statically controlled” it was almost impossible to establish deep core hierarchical drilling without kissing one’s life goodbye.

    example:
    Page
    – sub Page
    — sub sub Page
    — sub sub sub Page

    While I did establish hierarchical order to my Pages, I was unable to generate/pull multiple “information” into a “Parent” Page or even a deeply drilled sub-sub child page based on varying equations such as, date, author, post, category, etc…

    It was one “post” per page and that was it… Unless I totally missed the whole process (concept) of Pages entirely?

    It was one “post” per page and that was it…

    That’s what they are supposed to do.

    I use pages. Cause it gives me a better url structure. I leave the ‘posts’ concept for my blog-posts.

    To combat the ‘one post’ per page issue, I just executed an SQL query cause wordpress didn’t give me enough flexibility on that front.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Best way to do complex category pages?’ is closed to new replies.