Forums

[resolved] Do I need multiple templates or just one? (4 posts)

  1. 123kim
    Member
    Posted 2 years ago #

    I am very new to wordpress and PHP so please be kind...

    BACKGROUND:
    I have taken an existing theme and have extensively modified it to meet my specific needs and have just a little more work to do. I am creating a website for my students to post their assignments and other information they will need. Since I have 1st-5th grade students each week, I need to display a different set of posts and links for each grade level. (For this, I have one category called Assignments and then a sub-category for each grade.) I have also created a page for each grade. When I click on the link for each page, I want to see only the posts and links for a particular grade.

    After having read quite a bit in the codex and at other websites I am more confused!

    THE QUESTION:
    I would like to know if I need a separate template for each grade level which would have the sub-category hardcoded or can I use a single template and "pass" the appropriate sub-category to it. If one template will do, I'm a little confused what to do next. Any suggestions, advice, links to examples or specific documentation would be much appreciated!

    Thanks,
    KimB

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    You don't need separate category templates unless you want to do something special with 1 or more of the categories or sub-categories.

  3. 123kim
    Member
    Posted 2 years ago #

    Thanks for your reply. And just another related question if you don't mind.

    If I have the parent category of Assignments and a child category for each grade (1st, 2nd, 3rd, 4th, and 5th) what is the best way to specify the category for a particular page? For example, I can hardcode the category using the following query:

    <?php query_posts('cat=4'); ?>

    thus needing a separate template for each grade. OR, I could include an else if statement in the template as I've seen in the codex but this doesn't seem to be the best solution either.

    So, if a post or link is in a particular category (in my case category 4), what is the best way to select the category? How do I, using just a single generic template, when I click on the page that I've created, specify that I only want to see the posts and links assigned to category 4?

    Thanks in advance for you advice and patience.

  4. 123kim
    Member
    Posted 2 years ago #

    Maybe not the most elegant solution, but this is what I used:

    <?php if (is_page('17')) { query_posts('cat=4&showposts=1');}
    elseif (is_page('20')) { query_posts('cat=9&showposts=1');}
    elseif (is_page('21')) { query_posts('cat=10&showposts=1');}
    elseif (is_page('18')) { query_posts('cat=11&showposts=1');}
    elseif (is_page('19')) { query_posts('cat=12&showposts=1');}
    else { ?>
    <p>I didn't select a category</p>
    <?php } ?>

    would be interested in comments about other ways to solve the same problem

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags