Support » Plugins » Hacks » add dynamic category introduction

  • Hello,

    on my blog i have a couple of categories (each representing a specific country i have traveled). For each of these main categories, there are a couple of child categories (for each city/place i have traveled).
    There are no posts assigned to the parent categories, all posts are included in child categories only.

    Now when i am browsing the categories page of one of the parent categories i will recieve all posts of the child categories (i.e. will show all posts from subcategories like
    All these Categories pages just display one post per page, to make the archive readable a little bit like a book.
    Thats exactly what i want the categories pages to be, just with one small issue, so here my question:
    i want to add a dynamic page in front of all these posts, just like a sticky entry which is genereated dynamically and introduces the parent category. More specific:
    on there are now 23 posts/pages, whilch are correctly displayed in the wp-pagenavi.
    I want to add a dynamic entry as page 1, so the new count will be 24 pages, where the first post will be displayed on page 2.
    Oh, because i will add categories “on the road” with limited internet access, its essential for me that i dont have to “hard-code” anything like a sticky post for each new category.

    The dynamic introducion could be either a php condition in the category.php of my twenty eleven child theme, or speacial content template which will display dynamic content instead of a real post from the database.
    I just dont have any idea how to change the query to add this “first page” on each category, or if there is even a better way to do realize this.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    There may still be a better way, but I would alter the category.php template to output the introduction content when the current category is top level. Since all content from the DB only have child categories assigned, this will work fine. No need to query for some special introduction. In this introduction you can title with the current category. With the category name as title, you can use get_cat_ID() and use the ID in wp_list_categories() to list links to all the children and so all the posts in the category. You could also output whatever description you entered for the category was it was created. No need to alter this template when creating new categories, it will work properly with no intervention.

    If the current category is not top level, run the normal loop already on the template. In your case, this will result in a single post being displayed. The one glitch is if you are displaying page numbers. While it’s possible to change the numbering to accommodate this additional introduction page, it would be much easier to leave things as they are with the introduction as an un-numbered page. Much as book contents and prefaces etc. are not numbered and the book’s main content starts on page 1.

Viewing 1 replies (of 1 total)
  • The topic ‘add dynamic category introduction’ is closed to new replies.