为什么我的档案页面在所有帖子中循环,除了一个帖子?

时间:2020-07-12 作者:09eric09

我已经为我的自定义帖子创建了一个归档页面,它会循环浏览除第一篇以外的所有帖子。总共有11篇帖子,我在归档页面上只得到10篇。

Here is my archive template:

<div class="container">
  <h2 class="entry-title text-center pt-5">Market Place</h2>
  <p class="text-center">Filter providers by service and click on the logos shown below for more information and to contact a representative of the risk solution provider.</p>
  <div class="category-search-box text-center"><?php echo do_shortcode( \'[searchandfilter fields="provider,categories"]\' ); ?></div>
  <div class="row py-5">
    <?php if (have_posts()) : while (have_posts()) :the_post();
          $taxonomy = wp_get_object_terms($post->ID, \'categories\');
          $ids = "";

          foreach ($taxonomy as $cat) {
           $ids .= "cat-".$cat->term_id ." ";
         }
        ?>
      <div class="col-6 col-md-4 text-center">
        <div id="provider-archive-boxes" class="provider-archive-box <?php echo $ids; ?>">
          <a href="<?php echo the_permalink();?>"><?php the_post_thumbnail( \'full\', array( \'class\' => \'img-responsive\' ) ); ?></a>
          <p><strong><?php the_title();?></strong></p>
        </div>
      </div>
    <?php endwhile; ?>
    </div>
  <?php endif; ?>
</div>
Here is how I registered the post in the functions.php file:

function provider_setup_post_type() {
    $args = array(
        \'public\'    => true,
        \'label\'     => __( \'Providers\', \'textdomain\' ),
                "public" => true,
                "publicly_queryable" => true,
                "show_ui" => true,
                "show_in_rest" => false,
                "rest_base" => "",
                "has_archive" => \'marketplace\',
                "show_in_menu" => true,
                "exclude_from_search" => false,
                "capability_type" => "page",
                "map_meta_cap" => true,
                "hierarchical" => true,
                \'rewrite\' => array(\'slug\' => \'marketplace\'),
        \'menu_icon\' => \'dashicons-building\',
                "supports" => array( "thumbnail","post-thumbnail","title", "editor" ),
    );
    register_post_type( \'provider\', $args );

        register_taxonomy("categories", array("provider"), array("hierarchical" => true, "label" => "Categories", "singular_label" => "Category", "rewrite" => array( \'slug\' => \'marketplace\', \'with_front\'=> false )));
}
add_action( \'init\', \'provider_setup_post_type\' );

1 个回复
最合适的回答,由SO网友:mozboz 整理而成

正如@JacobPeattie所说,分页是造成这种情况的原因,如果你以后会有更多的帖子,你可能会想添加分页。

如果需要,可以在functions.php:

    function wpse_disable_pagination( $query ) {
        if (is_archive()) {
            $query->set(\'nopaging\', 1 );
        }
    }

    add_action( \'pre_get_posts\', \'wpse_disable_pagination\' );

相关推荐

Get Current User ID Inside a Loop返回0表示短码

我有一个函数,它对给定作者的所有帖子都有一个循环。我使用get_current_user_id() 但这在循环中似乎不起作用,或者可能是它的短代码问题。我的函数在shortcode的帮助下运行。当前用户总是返回0,因此它会显示我网站上所有帖子的元数据。function get_meta_value_by_meta_key(){ $author_id = \'get_current_user_id()\'; // do stuff to get user I $author