• Resolved Suffice

    (@suffice)


    This code (below) I need help with.. It does not seem to check the parent category ID, so it jumps right to the end… I appreciate any help! Thanks..

    <title>
    <?php if (is_single() || is_page() ) : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <?php
    $ep_category = get_the_category();
    
    if ($ep_category->category_parent == 498) { ?>
    Watch <?php the_title(); ?> 01010101011 | <?php
    $ep_title_category = $ep_category;
    echo $ep_title_category[0]->cat_name;
    }
    
    else if ($ep_category->category_parent == 500) { ?>
    Watch <?php the_title(); ?> 1010101101 | <?php
    $ep_title_category = $ep_category;
    echo $ep_title_category[0]->cat_name;
    }
    
    ?>
    
    <?php endwhile; endif; elseif(is_home()) : ?>
    0101010101101011
    <?php endif; ?>
    </title>
Viewing 2 replies - 1 through 2 (of 2 total)
  • $ep_category is a category object, as returned from get_the_category() – even if you only have one category in your post.

    if you only have one category in your post, try to use:

    if ($ep_category[0]->category_parent == 498) { ?>

    besides, categories are generally not defined in pages.

    Thread Starter Suffice

    (@suffice)

    That was it! That whole [0] I did not notice at all.. Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘If parent category is PHP/Functions help’ is closed to new replies.