Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

What is the correct way to write a conditional statement?

                    <?php if is_tag( 'Premium' ){
                     <a href="<?php the_permalink(); ?>" class="info"> Subscribe</a>

                    }else {

                    <a href="<?php the_permalink(); ?>" class="info">Read More</a>
                    }
                    ?>                   

Help Needed.

share|improve this question
    
are you want help in php formatting of your code? –  Ravs Dec 2 '13 at 17:26
    
yes, how can i add this in template. to show if the post has tag premium then show this or else. –  jamesrotcher Dec 2 '13 at 17:27
    
Personally, I would say the correct way to write any conditional is to add parenthesis around the statement: if(is_tag()) –  Howdy_McGee Dec 2 '13 at 18:18

2 Answers 2

up vote 0 down vote accepted

is_tag checks whether the page being displayed is the tag archive page for the named tag. It does not check whether the post in a Loop has that tag, which is what you ask: "...to show if the post has tag premium...". For that you need has_tag

if has_tag( 'premium' ){ ?>
    <a href="<?php the_permalink(); ?>" class="info"> Subscribe</a><?php
} else { ?>
    <a href="<?php the_permalink(); ?>" class="info">Read More</a><?php
}

Note that has_tag requires the tag slug and not the tag name, hence the lowercase.

share|improve this answer

try this

<?php if ( is_tag( 'Premium' ) ) : ?>
    <a href="<?php the_permalink(); ?>" class="info">Subscribe</a>
<?php else : ?>
    <a href="<?php the_permalink(); ?>" class="info">Read More</a>
<?php endif; ?>  
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.