将分页添加到wp查询

时间:2018-10-20 12:29:48

标签: php wordpress

我正在尝试向我的帖子查询添加分页。

我尝试在互联网上找到的所有样本都添加分页,但没有成功:/

这是我的查询代码以及尝试的分页代码:

            <?php

          $count = 0;

          // Query Code

          $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

          $wpb_all_query = new WP_Query(array('post_type'=>'post', 'category_name' => 'Recognitions', 'post_status'=>'publish', 'posts_per_page=3&paged=' . $paged));

          if ( $wpb_all_query->have_posts() ) :
              while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post();
              ?>

              <?php $linktab = 'http://' . "localhost:8888/Lemon/wordpress/?page_id=158" ."&featuredimage=".get_the_post_thumbnail_url(); ?>

                      <div class="wraper-tab
                      <?php

                      $count++;

                      $current_image = $_GET["featuredimage"];

                      if (!isset($current_image) && $count == 1) {
                        $_GET["featuredimage"] = get_the_post_thumbnail_url();
                        $current_image = get_the_post_thumbnail_url();
                      }

                      if ($current_image == get_the_post_thumbnail_url()) {
                        echo "active";
                      }

                       ?>
                      ">

                      <a class="mitch-button to-load dark" href="<?php echo $linktab ?>" data-i="1" data-title="Lapka">
                        <article class="tab vertical-center" data-background-l="dark" data-background-p="dark" itemscope itemtype="http://schema.org/CreativeWork">
                            <header class="page-header caption">
                                <div>
                                    <h6 class="tab-date"><?php echo get_the_date(); ?></h6>
                                      <h2 class="title" itemprop="name"><?php the_title(); echo $count;?></h2>
                                </div>
                            </header>
                            <div class="media">
                                <img src="" />
                            </div>

                        </article>
                        </a>
                      </div>

              <?php endwhile; ?>

        <?php
          else :
              _e( 'Sorry, no posts matched your criteria.' );
          endif;
        ?>
      </div>

      <?php
      // Pagination code
      next_posts_link();
      previous_posts_link();
       ?>

我要使它每页显示3个帖子。那就是为什么我在posts_per_page参数中添加了3。

我想要一个编号列表。

1 个答案:

答案 0 :(得分:0)

请使用此代码

    <button onclick="randomize()" type="button">Random Word</button>
    <p id="randomWord"></p>