StormShadow
StormShadow

Reputation: 1627

How do I check for a tag's existence in a post in Wordpress?

Quick question about Wordpress PHP: I am writing a theme and I want to display (on the main index page) one icon if my post has one tag, and another if it has the other.

I wrote something like

<?php has_tag('pc') { ?><img src="<?php bloginfo('template_directory'); ?>/images/pc-icon.gif"><?php }; ?>
<?php has_tag('mb') { ?><img src="<?php bloginfo('template_directory'); ?>/images/mb-icon.gif"><?php }; ?>

But it gives me an error. Can anybody help?

Thanks

Upvotes: 1

Views: 2366

Answers (2)

ariefbayu
ariefbayu

Reputation: 21979

try this:

<?php if(has_tag('pc')) { ?><img src="<?php bloginfo('template_directory'); ?>/images/pc-icon.gif"><?php }; ?>
<?php if(has_tag('mb')) { ?><img src="<?php bloginfo('template_directory'); ?>/images/mb-icon.gif"><?php }; ?>

Upvotes: 1

Tatu Ulmanen
Tatu Ulmanen

Reputation: 124768

<?php if(has_tag('pc')) { ?><img src="<?php bloginfo('template_directory'); ?>/images/pc-icon.gif"><?php }; ?>
<?php if(has_tag('mb')) { ?><img src="<?php bloginfo('template_directory'); ?>/images/mb-icon.gif"><?php }; ?>

You're missing the if.

Upvotes: 1

Related Questions