I’m pretty new to WordPress development. I have this code for a single page and it is outputting only the most recent post in an infinite loop. The page keeps getting longer and longer as the same post is called up again and again. How do I get it to show all the posts in order?
<?php
/*
* Template Name: Portfolio
*/
?>
<?php include 'header.php'; ?>
<div id="content">
<div id="content_inner">
<!--start the loop -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!--get posts-->
<?php query_posts('cat=uncategorized') ?>
<!--display the content-->
<?php the_content(); ?>
<!--end the loop-->
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div>
</div>
<?php include 'footer.php'; ?>
</div> <!--end allwrap-->
When you call
query_postsit re-executes a query on the database. Having this inside your loop is the cause of your infinite loop.You need to move the following line outside of the loop.
<?php query_posts('cat=uncategorized') ?>Which would give you something like this:
It is also important to add
wp_reset_query()