i want it to only display 1 blog post. how can i do that in the while loop? thanks
Do you understand that the while loop is specifically used to display multiple posts?
As another user points out, you can modify the query to only select one post. However, if you're working with the main query or another subquery that you cannot change, to display a single post, you don't need a while loop
query_posts('cat=1');
if (have_posts()) {
the_post();
the_title();
}
else {
echo 'sorry no posts';
}
If you must keep the while loop for whatever reason, you can break after the first one is displayed
while (have_posts()) {
the_post();
the_title();
break;
}
Last remark is about your use of if before while. It makes no sense
<?php if (have_posts()): while (have_posts()): the_post() ?>
...
<?php endwhile; endif; ?>
can be rewritten to
<?php while (have_posts()): the_post() ?>
...
<?php endwhile ?>