• Resolved nickaster

    (@nickaster)


    Howdy…. I have a special banner that appear on all post pages. It’s hard coded into the single.php page. However, I’ve no realized that once in a while I don’t want that banner to show. So I want to add some php around it so it doesn’t show up if the post is tagged with certain tags, let’s say “apples” and “bananas”.

    Anyone know the PHP to do this?

    ie:

    <if tag does not = apples or bananas >
    show this stuff
    <end if>

    Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • You want to use the is_tag function. http://codex.wordpress.org/Function_Reference/is_tag

    if ( !is_tag( array( ‘apple’, ‘banana’ ) ); ) {
    // show banner
    }

    That should do it. Not 100% sure that !is_tag will work properly. If not, you’ll have to remove the ! and just list all tags the banner should show on.

    if ( is_tag( array( ‘grape’, ‘orange’ ) ); ) {
    // show banner
    }

    Thread Starter nickaster

    (@nickaster)

    brilliant, thanks. But what’s the exact code including ?php I need to use HTML inside it? I’m thinking something like this?

    <?php if ( !is_tag( array( ‘apple’, ‘banana’ ) ); ) { ?>

    Bunch of stuff goes here

    <?php } ?>

    That seems to nuke my page, so something wrong!

    Oh, there is an extra ; in there that shouldn’t be.

    <?php if ( !is_tag( array( 'apple', 'banana' ) ) ) { ?>
    
    Bunch of stuff goes here
    
    <?php } ?>
    Thread Starter nickaster

    (@nickaster)

    ah!

    Well, no error now, but I’m afraid it didn’t work. I pased it verbatim as above and tagged a few posts “apples” and a few “bananas” and a few both and the “Bunch of stuff” still shows regardless…

    I was worried that the !is_tag may not work. Try:

    <?php if ( is_tag( array( 'grape', 'orange' ) ) ) { ?>
    
    Bunch of stuff goes here
    
    <?php } ?>

    I’ll try it too.

    I lead you down the wrong path. Sorry about that. Give me a moment.

    has_tag not is_tag 🙂

    <?php if ( !has_tag( array( 'apple', 'grape' ) ) ) { ?>
      This post is NOT tagged apple or grape.
    <?php } ?>
    
    <?php if ( has_tag( array( 'apple', 'grape' ) ) ) { ?>
      This post IS tagged apple or grape.
    <?php } ?>
    Thread Starter nickaster

    (@nickaster)

    Stupendous!

    We are in business. Thanks a million for your help.

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

The topic ‘PHP help? Probably easy’ is closed to new replies.