我几天来一直在讨论这个问题,所以希望能在这里找到解决方案。
我正在尝试显示来自自定义字段组的数据。这是我正在努力实现的示例布局
基本上,我正在尝试显示这些列的20 ++。但是,我只有11个来自这个自定义字段组。
这是我的页面模板代码:
<?php
/* Template Name: Branches Page */
get_header();
global $currentCity;
$registration_link = get_post_meta(96, 'registration_link', true);
$registration_text = get_post_meta(96, 'registration_text', true);
$thumbnail_url = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) );
?>
<!-- FEATURE IMAGE
================================================== -->
<?php if( has_post_thumbnail() ) { // check for feature image ?>
<section class="feature-image" style="background: url('<?php echo $thumbnail_url; ?>') no-repeat; background-size: cover;" data-type="background" data-speed="2">
<h1 class="page-title"><?php the_title(); ?></h1>
</section>
<?php } else { // fallback image ?>
<section class="feature-image feature-image-default" data-type="background" data-speed="2">
<h1 class="page-title"><?php the_title(); ?></h1>
</section>
<?php } ?>
<!-- MAIN CONTENT
================================================== -->
<div class="container">
<div class="row" id="primary">
<div id="content" class="col-sm-12>
<section class="main-content">
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; // end of the loop ?>
<?php $loop = new WP_Query( array( 'post_type' => 'branches_locations', 'orderby'=>'post_id', 'order'=>'ASC' ) ); ?>
<div class="resource-row clearfix">
<?php while( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
$resource_url = get_field('resource_url');
$address = get_field('address');
$city = get_field('city');
$branch_image = get_field('branch_image');
$senior_high_ready = get_field('senior_high_ready');
?>
<div class="resource">
<?php
if( $city <> $currentCity )
{
?>
<h2>
<?php echo $city; ?>
</h2>
<?php
}
else
{
?>
<h2 class="hidden-dummy-header">
Blank
<h2>
<?php
}
?>
<h3><?php the_title(); ?></h3>
<p><?php echo $address; ?></p>
<?php
if( $senior_high_ready == True)
{
?>
<h5 class="senior_high_ready">
SENIOR HIGH READY
</h5>
<?php
}
else
{
?>
<h5 class="hidden-dummy-header">
Blank
</h5>
<?php
}
?>
<img src="<?php echo $branch_image[url]; ?>" alt="<?php echo $branch_image[alt]; ?>">
<div class="register-link">
<a href="<?php echo $registration_link; ?>" class="btn btn-primary"><?php echo $registration_text; ?>
</a>
</div>
<?php $currentCity = $city; ?>
</div><!-- resource -->
<?php endwhile; ?>
</div><!-- resource-row -->
</section><!-- main-content -->
</div><!-- content -->
</div><!-- row -->
</div><!-- container -->
<?php get_footer(); ?>
是什么导致它不在我的自定义字段组中显示整个列表?
答案 0 :(得分:2)
默认情况下,WordPress将posts_per_page设置为10,因此您一次只能获得10个,除非您的代码中的其他位置更改了默认值。您可以通过将其设置为-1来获取所有帖子。像这样:
<?php $loop = new WP_Query( array( 'posts_per_page' => -1, 'post_type' => 'branches_locations', 'orderby'=>'post_id', 'order'=>'ASC' ) ); ?>
我希望有所帮助!
此外,您可以将其分成多行以提高可读性,例如:
<?php
$loop = new WP_Query( array(
'posts_per_page' => -1,
'post_type' => 'branches_locations',
'orderby'=>'post_id',
'order'=>'ASC'
) );
?>
顺便说一下,我将它称为自定义帖子类型而不是自定义字段组。 (仅供将来参考,如果您使用该术语,可能会获得更好的谷歌搜索结果。)