0
<?php $populargb = new WP_Query('showposts=5' );
    while ( $populargb->have_posts() ) {
        $populargb->the_post(); ?>
    <li>

    <a href="<?php the_permalink(); ?>">

        <div class="blog__list__img">
            <?php the_post_thumbnail(); ?>
        </div>
        <div class="blog__list__content">
            <h2 class="blog__list__content__h2"><?php the_title() ?></h2>
            <p class="blog__list__content__description"><?= get_the_excerpt(); ?></p>
            <span class="blog__list__content__date"><?php the_time("j F Y") ?></span>
        </div>

    </a>
    </li>
    <?php } ?>

Добрый день. У меня вот такой код. И я пытался сделать пагинацию, но у меня он не выводил ее. Вообще даже цифры страниц. Подскажите как добавить пагинацию ?

1
  • А что в этом коде отвечает за пагинацию? Она просто так не выводится сама по себе! 29 дек 2018 в 9:39

1 ответ 1

1

Посмотрите примерно вот это

<?php
// set the "paged" parameter (use 'page' if the query is on a static front page)
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

// the query
$the_query = new WP_Query( 'cat=1&paged=' . $paged ); 
?>

<?php if ( $the_query->have_posts() ) : ?>

<?php
// the loop
while ( $the_query->have_posts() ) : $the_query->the_post(); 
?>
<?php the_title(); ?>
<?php endwhile; ?>

<?php

// next_posts_link() usage with max_num_pages
next_posts_link( 'Older Entries', $the_query->max_num_pages );
previous_posts_link( 'Newer Entries' );
?>

<?php 
// clean up after the query and pagination
wp_reset_postdata(); 
?>

<?php else:  ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
3
  • Ой, с телефона как-то не так, поправлю с пк 29 дек 2018 в 9:46
  • Поправил уже... 29 дек 2018 в 10:00
  • Спасибо, с телефона реально неудобно код вставлять 29 дек 2018 в 10:09

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.