Forums

How do imake a conditional syays: if parent category is...? (10 posts)

  1. Begin
    Member
    Posted 2 years ago #

    i want to make wordpress use a specific template
    for all sub-categories in a specific category.

    i think it can be done with a conditional that
    that says: if parent category is...
    then use this template...

    does is one know if there is a way to do that?

    thank's

  2. Christian Schenk
    Member
    Posted 2 years ago #

    Have you had a look at the conditional tags? The function is_category should help you here.

  3. Begin
    Member
    Posted 2 years ago #

    I did, but isnn't that check's what is the category it self,
    and not it's parent category?

  4. Christian Schenk
    Member
    Posted 2 years ago #

    Oh sorry, didn't notice that you wanted the parent category. What about this?

    <?php
    $category = get_the_category();
    if ($category->category_parent == 42) {
    # use special template
    }
    ?>

  5. Begin
    Member
    Posted 2 years ago #

    I don't know it dosen't work,
    I need to put it in the "category.php"
    like that:

    <?php
    $category = get_the_category();
    if ($category->category_parent == 9) {
    # use special template
    }
    <?php include (TEMPLATEPATH . '/category-9.php'); ?>
    ?>

    right?

  6. Christian Schenk
    Member
    Posted 2 years ago #

    Put the line with the call to include inside the if statement - between the curly brackets - and remove the extra "<?php"/"?>" from this line.

  7. Begin
    Member
    Posted 2 years ago #

    Oh im so stupid, you right,

    But it's still dosen't work,
    it looks likt that now:

    <?php
    $category = get_the_category();
    if ($category->category_parent == 9) {
    include (TEMPLATEPATH . '/category-9.php');
    }
    ?>

    right?

  8. Christian Schenk
    Member
    Posted 2 years ago #

    Hm, have you read this? Maybe you just need to name the file with the above snippet right.

  9. Begin
    Member
    Posted 2 years ago #

    I did read it,
    but that means I need to make php files
    for all the categorys...

    There must be another easy way to that, don't you think?

  10. Begin
    Member
    Posted 2 years ago #

    I think i got a solution,
    it's not so simple, but what can i do... ?!

    it's here:
    http://brassblogs.com/blog/making-child-categories-recognize-parent-displays

    if any-one intrested...

    anyway thank you very much chschenk !

Topic Closed

This topic has been closed to new replies.

About this Topic