Support » Themes and Templates » Conditional text if there are no tags?

  • Resolved richardxthripp


    Can anyone tell me how to display certain text in the loop if a post has no tags, but the list of tags if there are tags? I want to show a sentence for each post that says: “By AUTHOR at DATE in CAT1, CAT2, with tags: TAG1, TAG2.”, but if there are no tags, end the category list with a period. I’ve got every piece but the last part. I’m trying this code:

    By <?php the_author_link(); ?> at <?php the_time(‘Y-m-d\TH:i:s’) ?> in <?php the_category(‘,’) ?><?php if (empty($tags)) echo “.”; else the_tags((‘, with these tags: ‘), ‘, ‘, ‘.’); ?>

    The ” if (empty($tags)) echo “.” ” just shows a period but no tags, even if the post has tags. For now, I’ve just removed the “if (empty($tags)) echo “.”; else” part. In a post with tags, it looks fine, of course (example). But in tagless posts, my sentence ends without a period (example). Won’t anyone save me?

    I’m using WordPress MU 2.5.1, but it shouldn’t matter since this part of it is the same as regular WordPress.

Viewing 1 replies (of 1 total)
  • I figured it out; just put the period outside the tags code. This does exactly what I wanted:

    By <?php the_author_link(); ?> at <?php the_time('Y-m-d\TH:i:s') ?> in <?php the_category(',') ?><?php the_tags((', with these tags: '), ', ', ''); ?>.

    If there are no tags, it just shows the period, and if there are tags, there are the tags, then the period. Didn’t think of that earlier for some reason.

Viewing 1 replies (of 1 total)
  • The topic ‘Conditional text if there are no tags?’ is closed to new replies.