• 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

Viewing 9 replies - 1 through 9 (of 9 total)
  • Have you had a look at the conditional tags? The function is_category should help you here.

    Thread Starter Begin

    (@bentalgad)

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

    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
    }
    ?>

    Thread Starter Begin

    (@bentalgad)

    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?

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

    Thread Starter Begin

    (@bentalgad)

    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?

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

    Thread Starter Begin

    (@bentalgad)

    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?

    Thread Starter Begin

    (@bentalgad)

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

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

    if any-one intrested…

    anyway thank you very much chschenk !

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How do imake a conditional syays: if parent category is…?’ is closed to new replies.