• I would like to show different options below my single post when a curtain tag is used.

    for instance if the tag dog is used i would like to make a link to a dog page

    i thought i could use is_tag but that does not seem to work.

    Any suggestions?

    Greetings,
    George

Viewing 9 replies - 1 through 9 (of 9 total)
  • is_tag is one way to do it. Another way would be to create a template called tag-dog.php.

    Thread Starter ghp123

    (@ghp123)

    the is_tag does not work is there a reason why it could not work in the single post?

    Hard to say since I have no idea what your code looks like. It would probably be easier to create a template such as tag-dog.php.

    http://codex.wordpress.org/images/1/18/Template_Hierarchy.png

    Hi ghp,

    I think the reason is_tag does not work for you is because that function is intended to detect whether or not the page being viewed is an archive page for a specific tag/all-tags…

    In order to achieve what you’re wanting to do, you’ll need to use the get_the_tags() function and then evaluate whether the desired term is contained in the list of returned tags.

    You might want to write a custom function in your theme’s functions.php file to handle this. Here is the func ref for get_the_tags():
    http://codex.wordpress.org/Function_Reference/get_the_tags

    Thread Starter ghp123

    (@ghp123)

    i tried with this piece of code

    <?php if (is_tag(‘peep’)) { ?>
    EXTRA INFO

    <?php } elseif (is_tag(‘batman’)) { ?>
    BATMAN

    <?php } elseif (is_tag(‘lost’)) { ?>
    LOST

    <?php } else { ?>
    ELSE

    <?php } ?>

    And it just seems to always take the else part.

    I don’t really know how to do to much in php and you totally lost me with the tag-dog.php part as i don’t have a clue how to do something like that

    ghp, see my earlier post… is_tag() is not intended to be used in the way you are looking for, that’s why you’re only getting the “else” response.

    you’ll need to use something like this:

    <?php
    $post_tags = get_the_tags();
    $tag_array = array();
    foreach($post_tags as $tag) {
      $tag_array[] = $tag->name;
    }
    if(in_array('dog',$tag_array) !== FALSE) {
    //show dog tag related code
    } else if(in_array('cat',$tag_array) !== FALSE) {
    //show cat tag related code
    } else if(in_array('pig',$tag_array) !== FALSE) {
    //show pig tag related code
    } else {
    //none of your special tags were found
    }
    ?>

    I haven’t had a chance to test this code as I’ve written it, but that should get you rolling in the right direction. I’ve used this before to show tag-specific opt-in forms to readers on a clients blog…
    I hope this helps!

    -greg

    the is_tag does not work is there a reason

    as @datdesignguy already said, is_tag() only works to identify a tag archive page;
    to check for tags in a post, try has_tag()
    http://codex.wordpress.org/Function_Reference/has_tag

    general http://codex.wordpress.org/Conditional_Tags

    it always makes sense to read the codex 😉

    Thread Starter ghp123

    (@ghp123)

    Thanks for all the help.

    The has_tag() seem to do the trick without me making to many changes.

    Yes! Thank you so much for this thread. The has_tag() is exactly what I was looking for.

    <?php if (has_tag(array('video',''))) { ?>
    <!-- don't show the image if there is a video-->
    
    <?php } else { ?>
    
    <div class="featuredImage"> <?php if ( has_post_thumbnail()) the_post_thumbnail(array( 504,378 )); ?> </div>
    
    <?php } ?>
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘tag makes something happen in single post HOW TO ?’ is closed to new replies.