If while statements within if loop on WordPress

I have written some basic PHP to get the Permalink and title of any post within a certain category. This was written for the footer and works just fine.

My issue is now when I try to use the same code within an if loop, it fails.

Read More

What should I be doing differently?

Here is my code:

<?php if (in_category('training'))
{

<?php query_posts('category_name=training'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>

}

elseif (in_category('club'))

{

<?php query_posts('category_name=club'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>

}

else

{

echo "Nothing to show";

}

 ?>

Related posts

Leave a Reply

1 comment

  1. Please use this
    
    <?php if (in_category('training'))
    {
    
     query_posts('category_name=training'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; endif; 
    
    }
    
    elseif (in_category('club'))
    
    {
    query_posts('category_name=club'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; endif; 
    }
    
    else
    
    {
    
    echo "Nothing to show";
    
    }
    
     ?>