正在寻求以下方面的帮助WP_Query
. 我正在学习创建WordPress主题,并通过创建房地产主题进行练习。我想做的是设置一个属性页(自定义帖子类型),显示自定义帖子类型的所有属性。
我的工作很好。我的问题是,当您单击某个特定属性以转到其单一列表页面(其中有更多详细信息)时,它将显示该自定义帖子类型中的所有属性,从最新添加的属性列表开始。
这是我的代码:
<div class="container">
<div class="row" id="primary">
<main id="content" class="col-sm-8" role="main">
<?php $property_listing = new WP_Query(array(
\'post_type\' => \'property\'
)); ?>
<?php while($property_listing->have_posts()) : $property_listing->the_post(); ?>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><?php the_title(); ?></h3>
</div>
<div class="panel-body">
<?php if ( has_post_thumbnail() ) { ?>
<div class="listing-feature">
<?php
the_post_thumbnail( \'large\', array( \'class\' => \'listing-feature\' ) ); ?>
</div>
<?php } ?>
<div class="panel-price row">
<div class="col-sm-4"><h2><?php the_field(\'property_price\'); ?></h2></div>
<div class="col-sm-8"><p class="pull-right"><strong>Suburb:</strong> <?php the_field(\'property_location\'); ?> <strong>|</strong> <strong>Type:</strong> <?php the_field(\'property_type\'); ?></p></div>
</div> <!-- /row -->
<hr id="customhr" />
<div class="listing-details row">
<div class="col-sm-6">
<p><strong>Listing ID:</strong> <?php the_field(\'listing_id\'); ?></p>
<p><strong>Land Size:</strong> <?php the_field(\'land_size\'); ?></p>
<p><strong>Construction:</strong> <?php the_field(\'construction\'); ?></p>
</div>
<div class="col-sm-6">
<p><strong>Bedrooms:</strong> <?php the_field(\'bedrooms\'); ?></p>
<p><strong>Bathrooms:</strong> <?php the_field(\'bathrooms\'); ?></p>
<p><strong>Car Spots:</strong> <?php the_field(\'car_spots\'); ?></p>
</div>
</div> <!-- /row -->
<hr id="customhr" />
<div class="row">
<div class="gallery">
<h3>Gallery:</h3>
<?php
$images = get_field(\'gallery_images\');
if( $images ): ?>
<?php foreach( $images as $image ): ?>
<div class="item-img col-md-3">
<a href="<?php echo $image[\'url\']; ?>" target="_blank">
<img class="gallery-img img-thumbnail" src="<?php echo $image[\'sizes\'][\'thumbnail\']; ?>" alt="<?php echo $image[\'alt\']; ?>" />
</a></div>
<?php endforeach; ?>
<?php endif; ?>
</div> <!-- /gallery -->
</div> <!-- /row -->
<hr id="customhr" />
<div class="row">
<div class="listing-description">
<h3>Description</h3>
<p><?php the_field(\'property_description\'); ?></p>
</div> <!-- /listing-description -->
</div> <!-- /row -->
<hr id="customhr" />
<div class="row">
<div class="listing-features">
<h3>Additional Features:</h3>
<?php
// check if the repeater field has rows of data
if( have_rows(\'additional_features_main\') ):
// loop through the rows of data
while ( have_rows(\'additional_features_main\') ) : the_row(); ?>
<strong class="feature-tags"><?php the_sub_field(\'additional_features\'); ?></strong>
<?php
endwhile;
else :
// no rows found
endif;
?>
</div><!-- /listing-features -->
</div> <!-- /row -->
<hr id="customhr" />
<div class="row">
<div class="listing-location">
<h3>Location:</h3>
<?php
$location = get_field(\'map_location\');
if( !empty($location) ):
?>
<div class="acf-map">
<div class="marker" data-lat="<?php echo $location[\'lat\']; ?>" data-lng="<?php echo $location[\'lng\']; ?>">
</div>
</div>
<?php endif; ?>
<div class="listing-address">
<?php the_field(\'map_location\'); ?>
</div>
</div> <!-- /listing-location -->
</div> <!-- /row -->
</div>
</div>
<?php wp_reset_query(); ?>
<?php wp_reset_postdata(); ?>
<?php endwhile; ?>
</main>