It's code I've acquired from the new WordPress 2.7 Cookbook:
<?php
query_posts('category_name=News');
if (have_posts()) : while (have_posts()) : the_post(); ?>
<h3><a href="<?php the_permalink() ?>" rel="bookmark" ><?php the_title(); ?></a></h3>
the_excerpt();
endwhile; else:
endif;
wp_reset_query();
?>
Does this need to be placed in something else?
I had a more obvious error in that code that is now fixed but still not working. Thanks in advance for any assistance. I want to know if this is an error in the book as well or if I'm just doing it wrong.
There are several unopened and unclosed PHP tags as I can see. Try this revised version:
<?php query_posts('category_name=News');
if (have_posts()) : while (have_posts()) : the_post(); ?>
<h3><a href="<?php the_permalink() ?>" rel="bookmark" ><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
<?php endwhile; else: ?>
<?php endif;?>
<?php wp_reset_query();?>
No it's only missing one opening PHP tag, the others you've added above are optional...
There should be an opening PHP tag before..
the_excerpt();
like..
<?php the_excerpt();
There's no need to switch in and out all the time, but for what it's worth it usually(well sometimes) makes the code easier to read and understand..
Yes, I agree, tr10os. Thanks for pointing that out.