There is no while/else
in PHP that I know of.
Second, I find “alternate” control structure syntax impossible to read, especially with two or three on the same line. Use brackets and properly indent your code. It will make a lot more sense.
<?php
$tags = wp_get_post_tags($post->ID); if ($tags) { ?>
<h3>Related</h3>
<?php $first_tag = $tags[0]->term_id; $args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),
'posts_per_page'=>10,
'caller_get_posts'=>1
);?>
<ul><?php
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) {
$my_query->the_post(); ?>
<li><h5><a href="https://wordpress.stackexchange.com/questions/105873/<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h5></li><?php
}
} else { // this is where the else goes; after the have_posts conditional
echo('no tags');
}
wp_reset_query(); ?>
</ul>
Noticed where I put the else
. It follows the if($my_query->have_posts)
conditional. If that condition is false
your else
should run, which sounds like what you want.