WP_Query Pagination
-
Hi,
I want to create a page to show all posts ranked by the number of comments. I created the template, linked it with the page in backend and get an list from all posts ordered by the number of comments.
Thats my code actually:
<?php $query = new WP_Query( array( 'orderby' => 'comment_count', 'order' => 'DESC' ) ); ?> <?php while ( $query->have_posts() ) : $query->the_post(); ?> <div class="col-sm-6 col-md-4 col-lg-4"> <div class="box"> <article class="post" id="post-<?php the_ID(); ?>"> <?php if ( has_post_thumbnail() ) : ?> <figure class="thumbnail"> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"> <?php the_post_thumbnail( array(480, 270) ); ?> </a> </figure> <?php endif; ?> <h2 class="entry-title"> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> </h2> <p class="preview"><?php echo wp_trim_words( get_the_content(), 13, '...' ); ?></p> </article> </div> </div> <?php endwhile; ?> <?php echo pagination(); ?> <?php wp_reset_postdata(); ?>
All works fine but it shows just as much posts as in the backend settings. Would be no problem if I would have a pager or pagination? index.php or search.php which have a loop all works with pagination. Just in my custom queries it doesnt work.
Anybody knows how to fix that problem?
best regards,
sascha
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘WP_Query Pagination’ is closed to new replies.