• <?php if (has_tag(array(‘tag1’, ‘tag2′,’tag3’))) $tg = $thetag(display the the tag that has);
    else $tg = ‘no tag found’;?>

    If someone can help me. i want the $tg variable get the tag that was found. Sorry for my bad english

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hmm… hope I understand your problem…

    <?php
    if( has_tag() ) {
    // IF THE POST HAS TAGS
    $tg = get_the_tags();
    }
    else {
    // IF NO TAGS
    $tg = ‘no tags found’;
    }
    ?>

    Pls try this… and let me know if it helps 😉

    Thread Starter adim32

    (@adim32)

    Is not working. Instead i get the tag i get Array

    Yes, I just put the tags in your $tg and added no output…
    If you dont really need the tags to be on your $tg you can use this way of showing or not showing the tags… couse the_tags(); will do that for you…

    <?php
    if( has_tag() ) {
      // IF THE POST HAS TAGS
      the_tags();
    }
    else {
      // IF NO TAGS
      echo 'no tags found';
    }
    ?>
    Thread Starter adim32

    (@adim32)

    i need to find if has one of the tag that i specific and show him. else no tags found

    Thread Starter adim32

    (@adim32)

    i found this

    [code moderated - please see forum guidelines for posting code]

    but this will show me Array if the tag not found and i want to show "no tag found".
    Can you help me?

    Ok, now i got it…
    i will try a solution… pls wait 😉

    try:

    <?php if (has_tag(array('tag1', 'tag2','tag3')))
    foreach( get_the_tags() as $tag ) {
    if( in_array( $tag->name, array('tag1', 'tag2','tag3') ) ) //use tag title - watch capitals and spelling
    { $tg = $tag->name; break; }
    }
    else $tg = 'no tag found'; ?>
    Thread Starter adim32

    (@adim32)

    alchymyth this is work verry well.
    Thanks alchymyth and egado for help.

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

The topic ‘has_tag Help’ is closed to new replies.