Smart Action "Show Posts" for Archive: Wrong per-page post count [fixed]

Creating an index.php for archives.
The loop shows one more post per page than set in WordPress settings.

Demo as screen recording (available for 30 days)

Can you send a link to your project or paste the HTML from your template in here so we can get a better idea of how you created this? Off the top of my head, I would guess that you have a placeholder card that you forgot to add the “do not export” action to, but that’s purely a guess based on boneheaded things I tend to mess up.

Here’s a screenshot of the structure panel:

The code:

<div class="container content-gap">
    <h1 cms-function="code" cms-function-type="content" cms-function-code="the_archive_title()">Archive Title</h1>
    <div cms-post="loop" cms-post-first-classes="card-post--first" cms-post-items-container=".archive-grid" cms-post-repeat=".card-post" cms-post-show-empty-element=".width-full">
        <ul class="archive-grid">
            <li class="card-post">
                <div class="card-post__media">
                    <figure>
                        <img src="https://pinegrow.com/placeholders/img10.jpg" class="card-post__image" loading="lazy" cms-post-image="medium">
                    </figure>
                </div>
                <div class="card-post__content">
                    <div class="card-post__content-left" style="flex-direction: column; display: flex;">
                        <h2 class="card-post__heading"><a href="" cms-post-link="not_singular" class="clickable-parent" cms-post-title>Post Heading</a></h2>
                        <p class="card-post__text" cms-post-excerpt>This is a paragraph, one or more lines of text. Each paragraph is displayed in a new line.</p>
                    </div>
                    <div class="card-post__content-right" style="display: flex; flex-direction: column; align-items: center;">
                        <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 96 960 960">
                            <path d="m304 974-56-57 343-343-343-343 56-57 400 400-400 400Z"/>
                        </svg>
                    </div>
                </div>
            </li>
            <li class="card-post" cms-no-export>
                <div class="card-post__media">
                    <figure>
                        <img src="https://pinegrow.com/placeholders/img10.jpg" class="card-post__image" loading="lazy" cms-post-image="medium">
                    </figure>
                </div>
                <div class="card-post__content">
                    <div class="card-post__content-left">
                        <h2 class="card-post__heading"><a href="" cms-post-link="not_singular" class="clickable-parent" cms-post-title>Post Heading</a></h2>
                        <p class="card-post__text" cms-post-excerpt>This is a paragraph, one or more lines of text. Each paragraph is displayed in a new line.</p>
                    </div>
                    <div class="card-post__content-right" style="display: flex; flex-direction: column; align-items: center;">
                        <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 96 960 960">
                            <path d="m304 974-56-57 343-343-343-343 56-57 400 400-400 400Z"/>
                        </svg>
                    </div>
                </div>
            </li>
            <li class="card-post" cms-no-export>
                <div class="card-post__media">
                    <figure>
                        <img src="https://pinegrow.com/placeholders/img10.jpg" class="card-post__image" loading="lazy" cms-post-image="medium">
                    </figure>
                </div>
                <div class="card-post__content">
                    <div class="card-post__content-left" style="flex-direction: column; display: flex;">
                        <h2 class="card-post__heading"><a href="" cms-post-link="not_singular" class="clickable-parent" cms-post-title>Post Heading</a></h2>
                        <p class="card-post__text" cms-post-excerpt>This is a paragraph, one or more lines of text. Each paragraph is displayed in a new line.</p>
                    </div>
                    <div class="card-post__content-right" style="display: flex; flex-direction: column; align-items: center;">
                        <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 96 960 960">
                            <path d="m304 974-56-57 343-343-343-343 56-57 400 400-400 400Z"/>
                        </svg>
                    </div>
                </div>
            </li>
        </ul>
        <div class="width-full" cms-template-part="template-parts/no-results">
            <p>Placeholder: Keine Ergebnisse</p>
        </div>
    </div>
    <div class="pagination-wrapper" cms-template-part="template-parts/pagination">
        <p>Placeholder: Pagination</p>
    </div>
</div>

Okay, this is going to drive me batty…

I just checked my template and it’s doing the same thing. To make it even more interesting, I switched to a vanilla Underscores theme, which also shows one more than what’s in the Reading settings in WordPress. Both Underscores and Pinegrow use a similar loop structure, which is also the same thing you’ll find in the WP Codex.

That tells me that it’s not a Pinegrow thing, but some WordPress oddity that I’m missing.

Maybe someone smarter than me knows the answer here.

Here is the relevant code from Underscores

		<?php
		if ( have_posts() ) :

			if ( is_home() && ! is_front_page() ) :
				?>
				<header>
					<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
				</header>
				<?php
			endif;

			/* Start the Loop */
			while ( have_posts() ) :
				the_post();

				/*
				 * Include the Post-Type-specific template for the content.
				 * If you want to override this in a child theme, then include a file
				 * called content-___.php (where ___ is the Post Type name) and that will be used instead.
				 */
				get_template_part( 'template-parts/content', get_post_type() );

			endwhile;

			the_posts_navigation();

		else :

			get_template_part( 'template-parts/content', 'none' );

		endif;
		?>

I don’t have this problem. 3 posts in the settings, 3 posts on the frontend.



I just noticed that GeneratePress also has this issue… I have to be missing something obvious!

Oh crap… in my tests, I have a sticky post. Those get added to the loop in addition to the post count. Could that be what you are seeing, @MichelyWeb?

it seems we might have found the root cause of your issue. :slight_smile:

Don’t worry, I have plenty more issues, and I’m sure they all have different root causes. :smiley:

@adamslowe Oh, I reassure you, I also regularly encounter situations where the rate of annoyance is inversely proportional to the simplicity of the cause …

And this, without even wanting to use the trendy features of WordPress!!

2 Likes

You’re right @adamslowe - I also have imported the theme test content and there is one sticky blog post. Did not know that sticky posts are counted on top of the query results. That’s weird behavior by WP IMHO.

Thanks so much guys!

1 Like