Sunday, July 27, 2025

Display Any Number of Posts in a WordPress Loop

Sometimes our readers send us special requests to change our website according to our wishes. One request was how to show as many posts as we want in WordPress loop as per our wish.

This option is not available by default in WordPress, so we have created a simple code for our users which works for this purpose.

WordPress loop is that part which checks every post and shows it on the page. It sees which post type or setting it matches and then shows that.

In this article, we will tell you in an easy way how you can show as many posts as you want on your website.

Want to stay ahead with AI-driven WordPress insights and stay updated with the latest trends? Subscribe for daily search insights at wpguidepro to improve your WordPress strategy!

What Is the WordPress Loop?

WordPress uses loop to display your posts. This is PHP code used within WordPress theme to display list of posts on website. This is an important part of WordPress and most of the queries are based on it.

Loop has different functions to display posts. But developers can customize it i.e. they can change template tags to display each post in their own style.

Example: Basic tags of loop show title, date and content. But you can also add custom tags like category of post, small excerpt, custom fields, author name and many more.

WordPress loop also gives you control over how many blog posts you want to show on each page. This feature is helpful when you are designing a page for an author and want only a few posts to be shown on that page.

Now let’s see how we can add the number of posts of our choice in WordPress loop.

Adding Any Number of Posts in a WordPress Loop

Usually in WordPress you can decide how many posts to show on a page.

For this, go to Settings » Reading section in WordPress dashboard. WordPress shows 10 posts in default settings.

adding number posts

But if you want, you can change this limit by using Super Loop. With Super Loop, you can show as many posts as you want on any page or section.

With this, you can set the design of your website according to your needs like author’s page, sidebar, or any other area.

First of all, you have to open the file where you want to show the posts. After that paste the loop below there

<?php
// Check if there are any posts available
if ( have_posts() ) :

    // Start with a post counter set to zero
    $count = 0;

    // Start the loop
    while ( have_posts() ) : the_post();

        // Stop the loop if 5 posts have been displayed
        if ( $count == 5 ) {
            break;
        }
        ?>

        <!-- Display each post inside a div -->
        <div class="post">
            <h2><?php the_title(); ?></h2> <!-- Display the post title -->
            <div class="content">
                <?php the_excerpt(); ?> <!-- Show a short summary of the post -->
                <!-- Use <?php the_content(); ?> instead if you want to show the full post -->
            </div>
        </div>

        <?php
        // Increase the post counter by 1
        $count++;

    endwhile;
endif;
?>

Note: In the if ( $count == “n” ) line in your code, you need to put your number in place of “n” – like 5, 10, or however many posts you want to show.

The easy way is to add this code to your WordPress site using the WPCode plugin.

WPCode is one of the best plugins used to manage custom codes in WordPress.

The advantage of this plugin is that you don’t have to manually edit theme files and there’s no risk of accidentally breaking anything. The WPCode plugin automatically inserts your code in the right place.

First of all you have to install and activate the WPCode plugin.

Once the plugin is activated, click on Code Snippets » + Add Snippet from the WordPress dashboard.

Then select the Add Your Custom Code option and paste your code there.

After that, you just need to paste the WordPress loop custom code we provided above in the ‘Code Preview’ box.

You will also need to give your code a name, like: Custom Post Loop or Show 5 Posts.

Then select the ‘Code Type’ option on ‘PHP Snippet’ as this is PHP code.

custom loop

Now scroll down until you see the ‘Insertion’ section.

From here you can decide in which part of the website your code should run.

By default, WPCode will run your code on the entire WordPress website.

But if you want, you can change the location and run the code only on a specific page or you can insert the code anywhere using a shortcode.

wordpress loop

When you have set everything, do not forget to put the toggle button on top to ‘Active’ so that the code gets activated.

Then click on the ‘Save’ button.

Now WPCode will apply your code in your WordPress blog and will show the number of posts you have set in the WordPress loop

Related Articles

- Advertisement -spot_img

Latest Articles