Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 自定义帖子类型实例都使用相同的特征图像(第一个)_Php_Wordpress_Wordpress Theming_Custom Post Type - Fatal编程技术网

Php 自定义帖子类型实例都使用相同的特征图像(第一个)

Php 自定义帖子类型实例都使用相同的特征图像(第一个),php,wordpress,wordpress-theming,custom-post-type,Php,Wordpress,Wordpress Theming,Custom Post Type,我在Wordpress中有一个自定义的post类型,它在functions.php中以以下方式定义: add_theme_support('post-thumbnails', array('post', 'my_custom_post_type' )); function my_custom_post_type() { $labels = array( 'name' => _x('MyCustomPostTypes', 'post type general na

我在Wordpress中有一个自定义的post类型,它在
functions.php
中以以下方式定义:

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
的第一个实例时,一切看起来都很棒。每个后续实例也是如此——除了所有这些后续实例上的特征图像与第一个相同之外。所有其他数据都正确,并且页面的Edit MyCustomPostType视图中显示的特征图像正确。所以我真的很困惑

我正在循环使用以下实例:

<?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
    }
?>
<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
实例的特征图像

非常感谢您对问题的任何见解或我应该在
wp\u 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; ?>

特色图像存储在post_元表中。这听起来像是一个循环问题,我想你在归档页面上有这个问题?谢谢你让我知道哪个表。我发现表格中的数据是准确的——帖子确实链接到了正确的缩略图。所以我仍然不明白为什么代码获取了错误的图像。同时,我在我的问题中添加了更多的细节,以显示我是如何循环的。对不起,你的意思是这个问题出现在单个帖子视图上吗?还是在帖子的归档列表上?如果是在单篇文章视图上,您能显示代码吗?问题是在单篇文章视图中,并且代码已经提供。这应该可以工作,您需要在单页上为
单篇文章缩略图()做一个循环。
在没有似乎已经完成的文章ID的情况下工作!谢谢你的耐心和帮助。