If you want has_tag()
to check for multiple tags, you must pass the list as an array. Right now, your elseif
statement is checking whether the post with the ID 127 has the tag with the ID 109, which probably isn’t what you wanted.
thanks for your replay. You are right. Now I tried with an array
<?php elseif (has_tag( array( 'Baby', 'Kindergartenkind' ) ) ) : ?>
And it checks only if one of these tags are in the array. So it displays again only one tag.
Then I found this Code Snippet:
<?php the_tags('<img src="'.get_bloginfo("template_url").'/images/icons/','.png" />'); ?>
But this simply displays all tags as images.
Well I guess it’s not possible..
Now that I read your last post, I think I might have misunderstood what you wanted. If you want to check whether a post has both tags, you could do this:
if ( has_tag( 'Baby' ) && has_tag( 'Kindergartenkind' ) : ?>
I think that is exactly what I need. Thanks! Just doesn’t display correctly (now I have the same icon twice for some reason?)
Is this correct?
<?php if (has_tag('Baby')) : ?>
<img src="<?php bloginfo('template_url'); ?>/images/mms-baby-icon.svg" onerror="this.onerror=null; this.src='<?php bloginfo('template_url'); ?>/images/icon_baby.png'" class="iconb">
<?php endif;?>
<?php if (has_tag('Kleinkind')) : ?>
<img src="<?php bloginfo('template_url'); ?>/images/mms-kleinkind-icon.svg" onerror="this.onerror=null; this.src='<?php bloginfo('template_url'); ?>/images/icon_kleinkind.png'" class="iconb">
<?php endif;?>
<?php if (has_tag('Kindergartenkind')) : ?>
<img src="<?php bloginfo('template_url'); ?>/images/mms-kindergartenkind-icon.svg" onerror="this.onerror=null; this.src='<?php bloginfo('template_url'); ?>/images/icon_kindergartenkind.png'" class="iconb">
<?php endif;?>
<?php if ( has_tag( 'Baby' ) && ( has_tag( 'Kleinkind' ) )): ?>
<img src="<?php bloginfo('template_url'); ?>/images/mms-baby-icon.svg" onerror="this.onerror=null; this.src='<?php bloginfo('template_url'); ?>/images/icon_baby.png'" class="iconb">
<img src="<?php bloginfo('template_url'); ?>/images/mms-kleinkind-icon.svg" onerror="this.onerror=null; this.src='<?php bloginfo('template_url'); ?>/images/icon_kleinkind.png'" class="iconb">
<?php endif;?>
<?php if ( has_tag( 'Kleinkind' ) && (has_tag( 'Kindergartenkind' ) )): ?>
<img src="<?php bloginfo('template_url'); ?>/images/mms-kleinkind-icon.svg" onerror="this.onerror=null; this.src='<?php bloginfo('template_url'); ?>/images/icon_kleinkind.png'" class="iconb">
<img src="<?php bloginfo('template_url'); ?>/images/mms-kindergartenkind-icon.svg" onerror="this.onerror=null; this.src='<?php bloginfo('template_url'); ?>/images/icon_kindergartenkind.png'" class="iconb">
<?php endif;?>
<?php if ( has_tag( 'Baby' ) && (has_tag( 'Kindergartenkind' ) )): ?>
<img src="<?php bloginfo('template_url'); ?>/images/mms-baby-icon.svg" onerror="this.onerror=null; this.src='<?php bloginfo('template_url'); ?>/images/icon_baby.png'" class="iconb">
<img src="<?php bloginfo('template_url'); ?>/images/mms-kindergartenkind-icon.svg" onerror="this.onerror=null; this.src='<?php bloginfo('template_url'); ?>/images/icon_kindergartenkind.png'" class="iconb">
<?php endif;?>
<?php if ( has_tag( 'Baby' ) && (has_tag( 'Kindergartenkind' ) && (has_tag( 'Kleinkind' ) ))) : ?>
<img src="<?php bloginfo('template_url'); ?>/images/mms-baby-icon.svg" onerror="this.onerror=null; this.src='<?php bloginfo('template_url'); ?>/images/icon_baby.png'" class="iconb">
<img src="<?php bloginfo('template_url'); ?>/images/mms-kleinkind-icon.svg" onerror="this.onerror=null; this.src='<?php bloginfo('template_url'); ?>/images/icon_kleinkind.png'" class="iconb">
<img src="<?php bloginfo('template_url'); ?>/images/mms-kindergartenkind-icon.svg" onerror="this.onerror=null; this.src='<?php bloginfo('template_url'); ?>/images/icon_kindergartenkind.png'" class="iconb">
<?php endif;?>
You’ll need to use some elseif
s in there so PHP parses correctly. Try this:
<?php if ( has_tag( 'Baby' ) && has_tag( 'Kindergartenkind' ) && has_tag( 'Kleinkind' ) ) : ?>
...
<?php elseif ( has_tag( 'Baby' ) && has_tag( 'Kindergartenkind' ) : ?>
...
<?php elseif ( has_tag( 'Baby' ) && has_tag( 'Kleinkind' ) : ?>
...
<?php elseif ( has_tag( 'Kindergartenkind' ) && has_tag( 'Kleinkind' ) : ?>
...
<?php elseif ( has_tag( 'Baby' ) : ?>
...
<?php elseif ( has_tag( 'Kindergartenkind' ) : ?>
...
<?php else ( has_tag( 'Kleinkind' ) : ?>
...
<?php endif; ?>