Forums

Problem with link posts to category template (8 posts)

  1. Begin
    Member
    Posted 2 years ago #

    I have this code in my "Single.php":

    <?php
    if ( in_category('3') ) {
    include 'single_article.php';
    }
    elseif ('category_parent=9') {
    include 'single_teacher.php';
    }
    else {
    include (TEMPLATEPATH . '/index.php');
    }
    ?>

    And it work's great to make every post under category3
    use "single_article.php" and every post under the category 9 or under one of it's subcategories use the "single_teacher.php".

    But when I try to add another template for posts
    under category 15 or it's subcategories like that:

    <?php
    if ( in_category('3') ) {
    include 'single_article.php';
    }
    elseif ('category_parent=9') {
    include 'single_teacher.php';
    }
    elseif ('category_parent=15') {
    include 'videolessons.php';
    }
    else {
    include (TEMPLATEPATH . '/index.php');
    }
    ?>

    It's just take the "single_teacher.php" even
    for the posts under category 15.

    Any Idea?

  2. Mark / t31os
    Moderator
    Posted 2 years ago #

    Is the category also a child of category 9 (id of 9) though?...

    If it is, that's why you have that problem, because the you get a match on the first elseif, so you never reach the next one...

  3. Begin
    Member
    Posted 2 years ago #

    No, it isn't.

  4. Mark / t31os
    Moderator
    Posted 2 years ago #

    Well exactly is this anyway?

    elseif ('category_parent=9')

    Unless you're passing that information along to something, that on it's own doesn't do anything, or shouldn't really do much anyway.

  5. Begin
    Member
    Posted 2 years ago #

    Sorry I didn't really understand what your saying :-)

  6. Mark / t31os
    Moderator
    Posted 2 years ago #

    What does this refer to?
    elseif ('category_parent=9')

    If category_parent ( what's category_parent ? ).

    As is, that's just a string of text that doesn't necessarily mean anything.

  7. Begin
    Member
    Posted 2 years ago #

    It is it means: chack if the post your on,
    is in a category that is a subcategory of category9,
    and it works!

  8. Mark / t31os
    Moderator
    Posted 2 years ago #

    Sorry that's my point, that code won't do that..

    Where did you take that code form?

Topic Closed

This topic has been closed to new replies.

About this Topic