<?php if (has_tag('keyword')) { ?> is the correct function but it needs to go inside the wordpress loop. Like so:
<?php while (have_posts()) : the_post(); ?>
<?php if (has_tag('keyword')) { ?>
<div class="post">
<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
<small><?php the_time('l, F jS, Y') ?></small>
<div class="entry">
<?php the_content() ?>
</div>
</div>
<?php }else{ ?>
something else
<?php } ?>
<?php endwhile; ?>
Tomontoast,
Thank you, works great.
Can I expand that and do this?
<?php while (have_posts()) : the_post(); ?>
<?php if (has_tag('keyword')) { ?>
<div class="post">
<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
<small><?php the_time('l, F jS, Y') ?></small>
<div class="entry">
<?php the_content() ?>
</div>
</div>
<?php }else{ ?>
<?php if (has_tag('keyword-2')) { ?>
something else
<?php }else{ ?>
<?php if (has_tag('keyword-3')) { ?>
something else
<?php }else{ ?>
something else
<?php } ?>
<?php endwhile; ?>
Thanks
You sure can, give it a go!
Sorry on closer inspection no that won’t work but you very close it should be:
<?php while (have_posts()) : the_post(); ?>
<?php if (has_tag('keyword')) { ?>
<div class="post">
<h3><a>"><?php the_title(); ?></a></h3>
<small><?php the_time('l, F jS, Y') ?></small>
<div class="entry">
<?php the_content() ?>
</div>
</div>
<?php }elseif (has_tag('keyword-2')) { ?>
something else
<?php }elseif (has_tag('keyword-3')) { ?>
something else
<?php }else{ ?>
something else
<?php } ?>
<?php endwhile; ?>
Excellent, thank you much for help!!! You’re great.
Question, from the code you posted above, what if I wanted to show the
<?php }else{ ?>
something else
<?php } ?>
<?php endwhile; ?
On post page as well as the non post pages like category and home page as well? Is that possible?
Thank you again.
That loop will work on any of your pages: archive page, single post page or front page.