how to get the category of the parent? (3 posts)

  1. photocurio
    Posted 5 years ago #

    I am using the following php on my site:
    <?php if (is_category('My Category')) { echo '<a href="http://linkhere.com">'; } ?>
    This is to add a link if something is in a particular category.

    I want to be able to use this on the image.php template, which doesn't have a category.

    Is there a way to re-phrase it to look at the category of the post that the image is attached to? i'd assume this is the category of the parent.

  2. Michael
    Part-Time Forum Moderator
    Posted 5 years ago #

    maybe using this
    in coordination with this
    might work.

    $post_id = get_post($post->ID);
    $parent_post_id = $post_id->post_parent;
    if (in_category( 'My Category', $parent_post_id )) { echo '<a href="http://linkhere.com">link<?a>'; }
  3. photocurio
    Posted 5 years ago #

    Wow. that works! I've been stumped on that little problem for days.

    site is here, btw: http://mumford-photo.com/

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.