0

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.

  • are you want help in php formatting of your code? – Ravinder Kumar 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. – luckyrajiv 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
1

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.

1

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; ?>  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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