• Resolved mriffey

    (@mriffey)


    <?php
    $posttags = get_the_tags();
    if ($posttags) {
      foreach($posttags as $tag) {
        echo '<img src="https://hateyourway.org/log/tags/' . $tag->term_id . '.png"
    alt="' . $tag->name . '" />';
    
    }}
    ?>

    What I am wanting to do is add some sort of else statement stating if that there is no tag selected it displays text in place of the original image.

    Meaning…if I tag my sister, it’ll display a picture corresponding to that number on the tag. If I tag no one in the post; I want it to display: No One Was Tagged. How would I go about this? Every time I try to add an else statement it gives me a string (unexpected) error.

Viewing 1 replies (of 1 total)
  • Thread Starter mriffey

    (@mriffey)

    … Figured it out. Combined what I saw in another posting to this.

    This is for people who want to display images as tags; but if there are no tags, display text stating that.

    Final Code:

    <?php
    $posttags = get_the_tags();
    if ($posttags) {
      foreach($posttags as $tag) {
        echo '<img src="Your Image URL Where Tag Images' . $tag->term_id . 'file extension"
    alt="' . $tag->name . '" />';
    
    }
    ?>
    <?php } else { ?>
    <p class="tags">No Tags Found</p>
    <?php } ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Displaying Default Tag Image’ is closed to new replies.