我在functions.php
中定义了一个自定义的Wordpress帖子类型:
add_theme_support('post-thumbnails', array('post', 'my_custom_post_type' ));
function my_custom_post_type()
{
$labels = array(
'name' => _x('MyCustomPostTypes', 'post type general name'),
'singular_name' => _x('MyCustomPostType', 'post type singular name'),
'add_new_item' => __('Add New MyCustomPostType'),
'edit_item' => __('Edit MyCustomPostType'),
'new_item' => __('New MyCustomPostType'),
'all_items' => __('All MyCustomPostTypes'),
'view_item' => __('View MyCustomPostType'),
'not_found' => __('No MyCustomPostTypes found'),
'not_found_in_trash' => __('No MyCustomPostTypes found in the trash'),
'parent_item_colon' => '',
'menu_name' => 'MyCustomPostTypes'
);
$args = array(
'labels' => $labels,
'description' => 'MyCustomPostType Here',
'public' => true,
'menu_position' => 5,
'supports' => array('title', 'editor', 'thumbnail'),
'has_archive' => true,
);
register_post_type('my_custom_post_type', $args);
}
add_action('init', 'my_custom_post_type');
当我创建MyCustomPostType
的第一个实例时,一切看起来都很好。每个后续实例——也是如此,除了,所有这些后续实例上的Featured Image与第一个相同。所有其他数据都是正确的,并且在页面的Edit MyCustomPostType视图中显示的Featured Image是正确的。所以我真的很困惑。
我像这样循环遍历实例:
<?php
while ($my_custom_post_types->have_posts()) {
$my_custom_post_types->the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title() ?></a></li>
<?php
}
?>
当我显示特定的帖子(即。 the_permalink
的目标),我这样做:
<section id="content" role="main">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h1><?php single_post_title(); ?> </h1>
</div>
</div>
<div class="row">
<div class="col-lg-3">
<figure>
<?php the_post_thumbnail('medium'); ?>
</figure>
</div>
<div class="col-lg-9 text">
<?php the_content(); ?>
</div>
</div>
</div>
</section>
但是正如我所说的,这个调用在每个情况下检索MyCustomPostType
按时间顺序的第一个实例的Featured Image。
任何对问题的见解或我应该在wp_posts
表中查看的内容都是非常感谢的。
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div class="row">
<div class="col-lg-12 text-center">
<h1><?php single_post_title(); ?> </h1>
</div>
</div>
<div class="row">
<div class="col-lg-3">
<figure>
<?php the_post_thumbnail('medium'); ?>
</figure>
</div>
<div class="col-lg-9 text">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; ?>