0

I'm a beginner developer so I'm sorry if I've made some obvious mistake, but I simply don't get why my loop for posts is not displaying all of my posts, I created 14 test posts and set the Reading options in Wordpress to display latest posts and put the number to 10, however, only 5 posts appear on the first page and when I click on 2nd page in the pagination there's only 1 post and my footer goes all the way up to the end of the post box instead of staying down on the 2nd page.

 <?php get_header(); ?>


<div class='containter containter--narrow page-section'>
        <?php if ( have_posts() ) : 
            while ( have_posts() ) : the_post(); ?>

        <article id="post-<?php the_ID(); ?>" class='post-item'>
        <h2><a class="post-title headline headline-medium" href='<?php the_permalink(); ?>'><?php the_title(); ?></a></h2>
        <hr>

        <div class='metabox'>Author: <?php the_author_posts_link(); ?> Published on: <?php the_time('d/M/Y'); ?> Categories: <?php echo get_the_category_list(', '); ?></div>

        <div class="post-excerpt content">
            <?php the_excerpt() ?>
            <p><a class='read-more' href="<?php echo get_permalink(the_post()); ?>">Read More &raquo;</a></p>       
        </div>

        </article>
    <?php endwhile; 
    endif; 
    echo paginate_links(); ?>
    </div>  

<?php get_footer(); 

?>
  • Does this answer your question? Override the default number of posts to show for a single loop? – BenB Apr 3 '20 at 14:58
  • I tried using the query solution they provided and it didn't help, I went to search for query_post on Wordpress docs and other posts but nothing seems to be helping me, I've tried a few different settings with it, and with all of them it's now displaying 6 same posts on 2 pages, like copied pages, still not able to see other posts tho – AcidBurn Apr 3 '20 at 15:20
  • @BenB that answer recommends using query_posts which is a terrible function you should never use. Avoid it like the plague. – Tom J Nowell Apr 3 '20 at 15:56
  • @AcidBurn are you using query_posts anywhere in your code? Never use that function, it will break your pagination and double the number of queries on your page. As for your code, under normal circumstances this should work as is, but plugins and filters can interfere. I also don't understand the reference to your footer, there is no footer code in your question, and I don't see how it impacts the pagination – Tom J Nowell Apr 3 '20 at 15:57
  • I only just added query_posts due to the previous reply, haven't used it anywhere else, and yes due to it posts have doubled. But the original problem of not displaying all posts (only 6 out of 14) is still not solved. I'm not using any plugins on the website, I just started making it few weeks ago and finished the header and footer area and now I'm moving to the blog section and faced this issue. I'm running it locally with Flywheel – AcidBurn Apr 3 '20 at 16:12
0

if anyone else is having the same problem as me, here is the solution. The problem that was causing this was

<?php echo get_permalink(the_post()); ?>

Honestly, I have no idea why I went with this instead of just the_permalink() , was having a problem with my read more button it was sending me to a different post than the post that was displaying, after removing get_permalink(the_post)) and replacing it with the_permalink() the problem was solved for both the read more button and for my previous problem. I can see all of the posts displayed on the website now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.