简体   繁体   中英

Wordpress loop is not showing all posts

I got lots of articles I show on my category page.

Here is the code.

<?php if(is_category(4)) { 
    while ( have_posts() ) : the_post(); ?>
        <div class="work">
            <div class="work-thumb">
                <a href="<?php echo get_permalink(); ?>">
                    <?php the_post_thumbnail(); ?>
                </a>
            </div>
            <div class="work-title">
                <a href="<?php echo get_permalink(); ?>"> <?php the_title(); ?></a>
            </div>
        </div>
    <?php endwhile; // end of the loop.
} ?>

It is just loop on all articles, but it doesn't show all of them, just like 50%

What could be the problem>?

Is the page that's using that template/code the page that you have set to be the Posts Page, in admin settings?

If so, then the posts per page setting could be less than the total number of posts (and you would need pagination, or to increase this number).

If it's a custom query with the code in your question, then you need to add this to the query arguments:

'posts_per_page' => -1

Note: Even if your case is the former, you could alter the query by using the pre_get_posts filter. Eg put this in your theme's functions.php :

add_action('pre_get_posts', 'my_filter');

function my_filter( $query ){
    $query->set('posts_per_page', -1);
    return $query;
}

Inside that function, you want to wrap the code inside an if statement, to do it specifically for the, for example, post type or taxonomy in question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM