I am trying to do a simple query to get the latest 5 posts into an unordered list, but this is only showing 1 result even though I have several posts. I even did an offset, but it shows the next post yet still 1 result. What am I doing wrong?
<ul>
<?php $the_query = new WP_Query('showposts=5'); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<li>
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
<p><?php the_content_limit(250); ?></p>
</li>
<?php endwhile;?>
</ul>
the_content_limit
does not exist in WordPress. You probably want something likethe_excerpt
.What’s likely happening is your loop is working fine, but the call to an undefined function causes the program to error out, making it appear the the loop is not working. Look at the rendered HTML: you’ll probably see a single, opening
<li>
tag, the link and an opening paragraph tag.showposts
is also deprecated. Take a look in the codex: dropped in 2.1Try this:
The default syntax for post_per_page is-