所以我的问题是我刚刚创建了一个自定义帖子类型,并创建了几个帖子来配合这个。我在我创建的模板 single-post_type.php 中使用 ACF 字段。这些在个别帖子上显示得很好,但我需要个别帖子页面上的一些 ACF 字段值显示在自定义帖子索引上。我试过寻找答案,但似乎找不到我要找的东西。
作为参考,这是我注册自定义帖子类型的代码:
// Add new post type for Available Homes
add_action('init', 'available_homes');
function available_homes()
{
$available_homes_labels = array(
'name' => _x('Available Homes', 'post type general name'),
'singular_name' => _x('Available Home', 'post type singular name'),
'all_items' => __('All Available Homes'),
'add_new' => _x('Add New Listing', 'recipes'),
'add_new_item' => __('Add New Listing'),
'edit_item' => __('Edit Listing'),
'new_item' => __('New Listing'),
'view_item' => __('View Listing'),
'search_items' => __('Search in Available Homes'),
'not_found' => __('No listings found'),
'not_found_in_trash' => __('No listings found in trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $available_homes_labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 20,
'supports' => array('title','editor','custom-fields'),
'has_archive' => 'available_homes'
);
register_post_type('available_homes',$args);
}
我在 single-available_homes.php 上有一些基本的 ACF 字段
然后我有一个名为archive-available_homes.php 的页面,其中包含以下代码:
<?php get_header(); ?>
<h1 class="page-title">Available Homes</h1>
<div id="primary">
<div id="content" role="main">
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts('') ) : the_post(); ?>
<?php get_template_part( 'content', get_post_type() ); ?>
<?php endwhile; ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->
<?php endif; ?>
</div><!-- #content -->
</div><!-- #primary -->
<div class="widget_area">
<?php dynamic_sidebar("gravity_form_widget_area"); ?>
</div>
<?php get_footer(); ?>
ACF 字段和其他所有内容在各个帖子上都运行良好,但我只是不知道该怎么做才能让 ACF 字段数据显示在存档页面上。帮助?