The code you posted does not query for any content at all. To do that, use the WP_Query
object. Please do not use query_posts
, especially for secondary Loops. From the Codex:
// The Query
$the_query = new WP_Query( $args );
// The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
endwhile;
All you need to do is provide $args
. In your case array('posts_per_page'=>3)
$args = array('posts_per_page' => 3); // or however many you want
// The Query
$the_query = new WP_Query( $args );
// The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
endwhile;
Related Posts:
- Strange switch_to_blog() issue
- Search widget breaks when using multiple loops?
- Display post category in foreach loop with category link
- Why WP_Query(‘showposts=5’) shows only 1 post?
- List authors with the last post title and order by last post date
- How can I remove the first two words and shorten get_the_title()
- Defining ‘last’ class on foreach blog posts
- Alternate row and columns every X posts
- page.php showing loop of posts and not page content
- Inserting custom data to the_post() during loop
- Adding specific post category between posts in loop
- How To Get Posts With A Specific Word
- Best way to assign post position in a news site homepage? (no categories, no sticky posts)
- How do I restart my loop with get_next_post()?
- WordPress Custom Fields (Checkboxes with multiple values)
- How to display posts on a static page? (like search loop)
- Child_of not displaying all children posts.. via get_posts
- Multiple loops are not reset
- I would like to have different styles for my posts based on the content of each post
- Most liked page not displaying posts
- Displaying Latest Posts on a Page
- Display all posts that were published before full post on single.php
- How to make number of blog posts a custom field?
- Exclude category from
- WordPress Loop – Next 3 Posts
- Blog post per page setting conflicting with custom WP_Query?
- How to exclude latest x posts from a paginated query?
- Two loops, one AJAX loop, exclude posts in first loop from second loop, loops are in different files
- problems with loading posts in a table-row
- Blog page pagination is not working after using the offset argument
- Posts will not display on page-mypage.php
- WP Query – Posts Per Page not working in combination with category__in
- How can I add extra word in permalink when someone click download button?
- More then one menu items are assigned with “current-menu-item” class
- Pausing and Resuming WP_Query results
- Pulling in post category and children within category
- Post Loop Missing Most Recent Post
- remove post that has no content
- Trying to use AngularJS with WordPress without any API
- How to : pagination in 3 different custom loops on the same page
- Pagination with an array of post objects?
- Sharing post from archive page (loop) doesn’t work
- Get Image tag from content of post
- Start WP Pagination From Number 1 in URL
- Creating a post from data returned from HTML form
- How to add tags (custom taxonomy) to post class css?
- Listing Specific Categories from Current Post with Depth
- How to exclude visited posts from loop
- Use two different post_per_page limits with infinite scroll
- wp_query random post
- How to make the first post in the loop be styled like a “new / featured” post?
- “Right Way” to make custom Loop respect reading settings inside admin panel?
- How to setup a query to output posts by groups of five?
- Only display sticky post or latest post in custom loop
- Display post category in foreach loop
- How to order posts in an arbitrary order?
- How do I stop the loop from repeating in my category template?
- get_the_category listing in hierarchial order
- How many posts does the loop return?
- Display Posts on Custom Page
- How to make a sum of all posts displayed in a loop
- Possible to alternate between two loops
- Exclude current custom post on single post
- Wrong post title displayed from loop
- Get Value of Post before
- why does wordpress ignore the post args?
- Multiple Loops Breaking Pages
- add to end of post in the loop with plugin
- Page template is accessing the incorrect posts?
- First x post with another template then the others
- Loop doesn’t show title of second post and posts thereafter
- Change all author links in Blog roll
- Grid post page on WordPress with Bootstrap, the_excerpt(); Problem
- Showing categories and subcategories with posts
- Second get_permalink inside loop points to wrong URL
- Get the amount of posts on a current page
- Loop parent terms {display posts} AND loop child terms {display posts}
- How to add a class to each individual post?
- add bootstrap post slider with tabs
- How to avoid duplicates when creating recent network posts
- How to add add more properties to WP_Post object in search results loop
- Custom taxonomy archive page problem
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- Loop don’t work within single.php page
- Use Click Image to Play Youtube Video in a WordPress Loop
- Can’t get full post title if there a spaces in title
- Get post meta retrieving wrong value
- Adding a user’s ID behind the tag ref link address
- older blog posts not showing in new theme
- How to get posts published on the latest date?
- The_excerpt() doesn’t parse – how to change that?
- Trying to edit archive.php to only show post extract, with featured image
- Add Blog to WP homepage Manually
- How to only publish posts with image in it
- How to show all posts by author on buddypress profile with navigation
- Page and post loop same template
- WordPress Query Posts From Category Post on Static Page
- ACF to select posts not displaying on blog page
- Add custom text automatically on each post
- Getting blog pagination to work on page set as front page