WordPress定制主题:我的网站在第一页和第二页上显示相同的帖子,依此类推

时间:2018-05-09 作者:Quentin Kaffka Genaamd Dengler

尽管分页转到nieuws/page/2,它仍然显示与第一页相同的帖子。这是我的博客PHP代码:

<!-- Tekst -->
<div class="page-wrapper" id="nieuws">
  <h1 id="over-ons-h1">Laatste <span>Nieuws</span></h1>
  <div class="lijn" id="text-lijn"></div>
</div>

<!-- Page Code -->
<div class="wrap">
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

      <!--  Posts Loop -->
      <?php
        $args = array(
          \'post_type\' => \'nutrisense_nieuws\'
        );

        $the_query = new WP_Query($args);

      ?>

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

      <div class="posts">
        <h2 class="post-title"><a class="post-title" href="<?php  the_permalink(); ?>".><?php the_title(); ?></a></h2>
        <div class="calender"><i class="far fa-calendar-alt"></i><p class="post-datum"><?php the_time(\'j F, Y\'); ?></p></div>
        <div class="post-thumbnail"><?php the_post_thumbnail(); ?></div>
        <div class="post-tekst-wrapper"><p class="post-tekst"><?php the_excerpt(); ?></p></div>
        <p class="post-lees-meer"><a class="post-title" href="<?php  the_permalink(); ?>".>Lees meer..</a></p>
        <?php endwhile;?>
        <?php
        previous_posts_link(\'&laquo; Nieuwere berichten\');
        next_posts_link( \'Oudere berichten &raquo;\', $the_query->max_num_pages );
        wp_reset_postdata();
        ?>

        <?php endif; ?>
      </div>

        </main><!-- #main -->
    </div><!-- #primary -->
</div><!-- .wrap -->

1 个回复
SO网友:Bikash Waiba

你需要通过posts_per_pagepaged 参数。

    $args = array(
      \'post_type\' => \'nutrisense_nieuws\',
      \'posts_per_page\' => get_option(\'posts_per_page\'); // number of posts to show per page  
      \'paged\' =>  get_query_var( \'paged\', 1 ) // get page if set else page 1, Use "page" for static front page instead of "paged" see the links. 
    );

    $the_query = new WP_Query($args);
先检查这些

Get Query Var

WP Query

结束

相关推荐

COUNT_USER_POSTS函数的自定义查询

我正在使用一个插件来显示我网站后端的用户帖子数。插件在循环中使用“count\\u user\\u posts”函数来显示所有用户的帖子数量。我想修改“count\\u user\\u posts”函数的$count值,这是一个sql查询,并在最后附加更多的条件。i、 e和post\\u日期介于“$startDate”和“$endDate”之间。函数将$count query、$userId作为参数返回“get\\u usernumposts”的挂钩。//wp function function