• Resolved rjpinney

    (@rjpinney)


    I need an if statement to include in my category template. I want to show some information, but only if the category that is being viewed is a parent category.

    Can anyone advise on what conditional statement I need to use here?

    <?php if ( ?????? ) : ?>

    Thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • try this:

    $category = get_the_category();
    if ($category->category_parent !== '') {
    # code here
    }
    Thread Starter rjpinney

    (@rjpinney)

    Thanks for your response, I’ve put that in but it crashes the page if I try and put code (or anything) into it – I may have implemented it wrong.

    This is what I have:

    <?php
    $category = get_the_category();
    if ($category->category_parent !== '')
    { }
    ?>

    Try if ($category->category_parent != '')

    oops thanks esmi 😛

    Thread Starter rjpinney

    (@rjpinney)

    I’m afraid I’ve still got the same problem..

    paste your exact code please…

    Thread Starter rjpinney

    (@rjpinney)

    <?php
    $category = get_the_category();
    if ($category->category_parent != '')
    {  }
    ?>

    If I put anything in the area you entered for code, it crashes the page.

    I want to then list the child categories as links, if that makes any difference.

    Thanks for all your help, appreciated!

    Tried and tested on my own site here you go:

    <?php
        $category = get_the_category();
        if ($category[0]->category_parent != '') {echo 'hello world!' ;} ?>
    Thread Starter rjpinney

    (@rjpinney)

    Thanks so much, it’s working!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘If conditional statement – if category is a parent category’ is closed to new replies.