【问题标题】:Wordpress displays 10 post type itemsWordpress 显示 10 个帖子类型项目
【发布时间】:2026-02-13 15:45:01
【问题描述】:

我使用 自定义帖子类型 UI Wordpress 插件创建了一个自定义帖子类型(场地)和一个自定义分类(场地类型) .然后我创建了大约 65 个 Venue 项目,并尝试使用以下循环脚本在页面上显示它们。不幸的是,每个场地类型的结果仅限于 10 个场地项目。任何想法为什么?

        <?php 

          $args = array(
              'orderby' => 'name',
              'hide_empty' => true,
              'taxonomy' => 'venue_type'
          );
          $categories = get_categories($args);

          foreach( $categories as $category ) {
            echo '<div class="ui-accordion-header">';
              echo "<div>";
                echo "<h3>" . $category->name . "</h3>";
                echo "<p>" . $category->description . "</p>";
              echo "</div>";
            echo "</div>";
            $newargs = array(
             'post_type' => 'venue',
             'tax_query' => array(
              array(
               'taxonomy' => 'venue_type',
               'field' => 'slug',
               'terms' => $category->slug
              )
             )
            );

            echo '<div>';
              echo "<div>";
                echo '<ul class="cs-grid cs-style">';
                  query_posts( $newargs );
                  if (have_posts()) :
                      while (have_posts()) : the_post();
                        echo "<li>";
                          echo "<figure>";
                            the_post_thumbnail();  
                            echo "<figcaption>";    
                              echo "<h3>"; 
                                the_title(); 
                              echo "</h3>";
                              echo "<span>"; 
                                the_field('location');
                                echo " "; echo "|"; echo " ";
                                echo 'Capacity'; echo " "; the_field('capacity');
                              echo "</span>";
                            echo "</figcaption>";
                          echo "</figure>";  
                        echo "</li>";
                      endwhile;
                  endif;
                echo "</ul>";
              echo "</div>";
            echo "</div>";

          }

       ?>

【问题讨论】:

    标签: php wordpress wordpress-theming custom-post-type


    【解决方案1】:

    查看 Wordpress 管理页面中的“设置 -> 阅读”页面。您可以在此处配置每个列表页面应显示多少帖子。

    这篇博文也很有用:http://weblogs.about.com/od/wordpresstutorialstips/tp/How-To-Configure-Wordpress-Reading-Settings-For-Your-Blog.htm

    祝你好运!

    /威尔

    【讨论】:

    • 在事情的范围内,你的答案还可以,但如果该链接永远变暗,最好包含上面链接中的规范示例。
    • 感谢您的建议。我对在 * 上写答案比较陌生。将来会牢记这一点! :)
    【解决方案2】:

    这可能是因为您将其设置为每页仅显示 10 个项目。添加'posts_per_page' =&gt; -1, 应该可以。

    $newargs = array(
             'post_type' => 'venue',
             'tax_query' => array(
              array(
               'taxonomy' => 'venue_type',
               'field' => 'slug',
               'terms' => $category->slug
              )
    

    会变成

    $newargs = array(
             'post_type' => 'venue',
             'tax_query' => array(
              array(
               'taxonomy' => 'venue_type',
               'field' => 'slug',
               'terms' => $category->slug,
                'posts_per_page' => -1
               )
    

    【讨论】: