自定义帖子的缩略图未显示在查询中

时间:2013-12-09 作者:user2960468

当我进行查询时,我的缩略图不会显示在自定义帖子类型中,但是它们会显示在single.php 文件

我已添加\'supports\' => array(\'title\',\'editor\',\'author\',\'thumbnail\',\'excerpt\',\'comments\') 我知道这不是问题所在。我正在获取查询中的其余数据,如下所示,但图像应位于文本上方:enter image description here

我没有在显示特色图像的单个页面中出现此问题:

enter image description here

我正在注册我的自定义帖子类型,如下所示:

add_action(\'init\', \'video_custom_init\');    

/* SECTION - video_custom_init */
function video_custom_init()
{
    // the remainder code goes here
}
/* #end SECTION - video_custom_init --*/

// The following is all the names, in our tutorial, we use "video"
    $labels = array(
        \'name\' => _x(\'videos\', \'post type general name\'),
        \'singular_name\' => _x(\'video\', \'post type singular name\'),
        \'add_new\' => _x(\'Add New\', \'video\'),
        \'add_new_item\' => __(\'Add New video\'),
        \'edit_item\' => __(\'Edit video\'),
        \'new_item\' => __(\'New video\'),
        \'view_item\' => __(\'View video\'),
        \'search_items\' => __(\'Search videos\'),
        \'not_found\' =>  __(\'No videos found\'),
        \'not_found_in_trash\' => __(\'No videos found in Trash\'),
        \'parent_item_colon\' => \'\',
        \'menu_name\' => \'video\'
    );

    // Some arguments and in the last line \'supports\', we say to WordPress what features are supported on the video post type
    $args = array(
        \'labels\' => $labels,
        \'public\' => true,
        \'publicly_queryable\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'query_var\' => true,
        \'rewrite\' => true,
        \'capability_type\' => \'post\',
        \'has_archive\' => true,
        \'hierarchical\' => false,
        \'menu_position\' => null,
        \'supports\' => array(\'title\',\'editor\',\'author\',\'thumbnail\',\'excerpt\',\'comments\')
    );

    // We call this function to register the custom post type
    register_post_type(\'video\',$args);
我对这个问题很困惑。这可能很简单。

用于显示自定义帖子的查询。

<?php if ( have_posts() ) : ?>

<?php $args = array( \'post_type\' => \'video\', \'posts_per_page\' => 3 );
            $loop = new WP_Query( $args );
                while ( $loop->have_posts() ) : $loop->the_post(); 

                    get_template_part( \'/templates/content-3col\');

                    endwhile;?>

            <?php endif; ?>
col3中的代码。php

<div class="col-md-4">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <header class="page-header" style="border-bottom:none; margin-bottom:0;">
        <?php if ( \'post\' == get_post_type() ) : ?>
        <div style="margin-bottom:5px;">
        <a href="<?php the_permalink(); ?>" rel="bookmark">
    <?php   if ( has_post_thumbnail() ) {
            the_post_thumbnail(\'col-6-thumb\');

                } ?>
        </a>
        </div>
        <?php endif; ?>
            </header>


        <div class="article-info">
        <div class="article-date"><h3><?php the_time(\'M jS\') ?></h3></div>
        <div class="articletitle"><h3><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h3><p>by <?php the_author() ?></p></div>
                </div>  
    </article><!-- #post-## --> 
</div>

1 个回复
最合适的回答,由SO网友:Subharanjan 整理而成

<div class="col-md-4">
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <header class="page-header" style="border-bottom:none; margin-bottom:0;">
            <div style="margin-bottom:5px;">
                <a href="<?php the_permalink(); ?>" rel="bookmark">
                <?php   if ( has_post_thumbnail() ) {
                the_post_thumbnail(\'col-6-thumb\');
                } ?>
                </a>
            </div>
        </header>
        <div class="article-info">
            <div class="article-date"><h3><?php the_time(\'M jS\') ?></h3></div>
            <div class="articletitle"><h3><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h3><p>by <?php the_author() ?></p></div>
        </div>  
    </article><!-- #post-## --> 
</div>
您可以将此代码放在您使用的模板文件中吗get_template_part( \'/templates/content-3col\');

Note: 当您查询帖子类型“视频”时,应该将帖子类型改为“视频”。这里您正在检查“post”<?php if ( \'post\' == get_post_type() ) : ?> 导致问题的原因。我刚刚删除了它。

结束

相关推荐