Follow us:
Want to show only three featured posts on your homepage? Or display ten recent posts from a category — without affecting your global settings?
By default, WordPress controls the number of posts through Settings → Reading → “Blog pages show at most”, but that applies site-wide.

In this guide, we’ll show you three clean and modern ways to display any number of posts — anywhere — using either code or the block editor.
You’ll learn:
- How to use a custom
WP_Queryfor complete control - How to create a shortcode for flexible placement
- How to use the Query Loop block visually in the Block Editor
All three work without extra plugins.
Method 1 — Use a Custom WP_Query for Full Control
This is the classic and most reliable approach.
You create your own query, specify exactly how many posts you want, and output them independently from the main loop.
<?php
$args = array(
'posts_per_page' => 5, // Number of posts to show
'post_type' => 'post', // Could be any CPT
'post_status' => 'publish',
);
$custom_loop = new WP_Query( $args );
if ( $custom_loop->have_posts() ) :
while ( $custom_loop->have_posts() ) : $custom_loop->the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('post-item'); ?>>
<h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="entry-summary"><?php the_excerpt(); ?></div>
</article>
<?php endwhile;
wp_reset_postdata();
endif;
?>
Why it’s recommended
- Doesn’t interfere with the global loop or pagination.
- Lets you query by post type, taxonomy, author, date, or keyword.
- Works in templates, widgets, or anywhere PHP runs.
Use this method when you’re building a custom section in a theme file or a page template.
Method 2 — Create a Reusable Shortcode (Add to functions.php)
If you want the same flexibility but inside the block or classic editor, wrap that query in a shortcode.
Add this to your child theme’s functions.php:
function wpp_posts_shortcode( $atts ) {
$atts = shortcode_atts( array(
'count' => 5,
'type' => 'post',
), $atts, 'wpp_posts' );
$q = new WP_Query( array(
'posts_per_page' => intval( $atts['count'] ),
'post_type' => sanitize_text_field( $atts['type'] ),
'post_status' => 'publish',
) );
ob_start();
if ( $q->have_posts() ) {
while ( $q->have_posts() ) {
$q->the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('post-item'); ?>>
<h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="entry-summary"><?php the_excerpt(); ?></div>
</article>
<?php }
wp_reset_postdata();
}
return ob_get_clean();
}
add_shortcode( 'wpp_posts', 'wpp_posts_shortcode' );
Now you can drop this anywhere in your content:
[wpp_posts count="3"]
Or use different post types:
[wpp_posts count="6" type="product"]
Why it’s handy
- Editors can control how many posts show up without touching PHP.
- Works in any page, post, or block that accepts shortcodes.
- Easily reusable across the site.
Method 3 — Use the Query Loop Block (No Code Needed)
Since WordPress 5.8, the Query Loop block lets you create dynamic post listings visually — directly in the Block or Site Editor.
How to use it
Open any page, post, or template.
Click the + Add Block button and search for “Query Loop.”

There are plenty of Query Loop layouts to choose from. Click on Start Blank to create your Query Loop from scratch.

Choose a layout (grid, list, cards, etc.).

In the right-side panel, open Display Settings (You may need to select the query type ‘custom’).
Set Items per page to any number you like.

Optionally, filter by category, tag, or author.
Customize the nested blocks (featured image, title, date, excerpt, etc.).
You can delete the pagination at the bottom of the block if you don’t need it. To do this, simply click on it, and click the ‘Three Dots’ options menu.
Then, click on ‘Delete’.

Why it’s powerful
- 100 % visual, no PHP edits.
- Perfect for Full Site Editing (FSE) themes.
- Instantly shows how many posts appear.
- Works with patterns and templates.
⚠️ When not to use it
If your theme is not block-based (classic PHP templates), stick with WP_Query or the shortcode method.
Summary — Pick What Fits You Best
| Method | Skill Level | Best For | Works In |
|---|---|---|---|
| Custom WP_Query | Intermediate | Developers, theme customization | Template files |
| Shortcode | Beginner – Intermediate | Editors who want quick control | Pages / Posts |
| Query Loop Block | Beginner | Block themes, visual design | Block Editor / Site Editor |
WordPress gives you several elegant ways to control how many posts appear — from developer-friendly PHP loops to the intuitive Query Loop block.
For classic themes, a custom query or shortcode offers the best control.
For block themes, the Query Loop block makes it effortless and visual.
Either way, you’re no longer bound by the global “posts per page” setting — you decide exactly how many posts appear, and where.



