【问题标题】:Wordpress custom field only displaying 10 postsWordpress 自定义字段仅显示 10 个帖子
【发布时间】:2013-08-07 16:19:02
【问题描述】:

我使用了 wordpress 高级自定义字段 插件来制作我的投资组合页面。我已经设置了图片、标题、类别的字段,并为该项目的特色天气设置了是/否。

我的项目页面代码如下:

<?php

    $args = array(
        'post_type' => 'project'
    );

    $query = new WP_Query( $args );

?>

<?php Starkers_Utilities::get_template_parts( array( 'parts/shared/html-header', 'parts/shared/header' ) ); ?>

<h1 class="lead"><?php the_title(); ?></h1>

<div id="triggers">
    <strong>Filter:</strong>
    <span id="filterDouble">Filter All</span>   
    <span id="filter1">Filter 1</span>
    <span id="filter2">Filter 2</span>
</div>

<ul id="gallery" class="group">
    <?php if ( have_posts() ) while ( $query->have_posts() ) : $query->the_post(); ?>

        <li class="gallery_image" data-id="id-" data-type="<?php the_field('project_category')?>">

                <a rel="prettyPhoto[gallery]" class="zoom" href="<?php echo the_field('image') ?>">

                    <img class="mag" src="<?php bloginfo('template_url'); ?>/imgs/mag.png"/><div class="thumb_bg"></div>
                    <?php the_post_thumbnail('portfolio'); ?>
                </a>                                    


        </li>
    <?php endwhile; ?>
</ul>

一切正常,我可以添加项目。然而,当我完成 10 个项目时,我的问题就开始了。 10 之后就不再显示了。我正在使用 jpages(jquery 插件)和 filtrify 来添加过滤器以过滤类别。他们工作正常,我可以按类别过滤,我看到正确的图像。即使删除了插件脚本,我仍然最多只能看到 10 个帖子。添加超过 10 个只会将较早的图像推开,并显示 10 个最新的图像。

那么我怎样才能阻止它只有 10.. 我的 jpage 脚本将分页设置为每页 12,但这甚至没有机会开始。我认为这是一个帖子问题,因为我是肯定不是脚本。

我想我发现了一个问题 - 我对此进行了测试:'posts_per_page' =&gt; '20' - 确实显示了我丢失的帖子,但是我不想设置一个数字,因为我可能需要很多。我如何定义无限数量。提供这是问题..

如果需要任何其他代码,请告诉我,但我认为这是控制我的帖子出现在页面上的主要部分。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    您在正确的轨道上。将值设置为 -1 以获得您想要的结果。

    文档链接:http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters

    posts_per_page (int) - 每页显示的帖子数(在 2.1 版中可用,已替换 showposts 参数)。 使用 'posts_per_page'=>-1 显示所有帖子。如果使用该参数后关闭分页,则设置'paged'参数。

    【讨论】:

    • 啊,我不敢相信我没有找到 :) 谢谢!
    • 你需要单引号中的 -1 吗?
    猜你喜欢
    • 1970-01-01
    • 2014-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多