【问题标题】:Why is my secondary featured image not showing in using Wordpress?为什么我的次要特色图片在使用 Wordpress 时没有显示?
【发布时间】:2010-08-05 10:17:23
【问题描述】:

我正在使用 wordpress 并且正在使用特色图片(它们曾经被称为帖子缩略图)。我想使用多张精选图片,所以我选择使用Multiple Post Thumbnails Plugin

我可以让二级图像上传框显示在管理区域中,但我无法设法让图像显示在页面上。

这是我用来尝试显示的代码(来自:http://wordpress.org/extend/plugins/multiple-post-thumbnails/installation/):

<?php if (class_exists('MultiPostThumbnails')
    && MultiPostThumbnails::has_post_thumbnail('post', 'secondary-image')) :
        MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image'); endif; ?>

我尝试在 if 语句中添加一个随机回显,以查看它是否被命中,但它没有回显,所以我猜测不满足条件?

我错过了什么?

【问题讨论】:

    标签: wordpress file-upload


    【解决方案1】:

    首先,我想也需要启用缩略图:

    // This theme uses post thumbnails
    add_theme_support( 'post-thumbnails' );
    

    然后你必须添加类似的东西

    if (class_exists('MultiPostThumbnails')) {
        $types = array('post', 'page', 'my_post_type');
        foreach($types as $type) {
            $thumb = new MultiPostThumbnails(array(
                'label' => 'Secondary Image',
                'id' => 'secondary-image',
                'post_type' => $type
                )
            );
        }
    }
    

    theme_setup() {...} 函数内的主题functions.php 文件中。

    HTH,mtness。

    【讨论】:

    • 什么是theme_setup函数?
    • 我发现了我的错误。我没有将它放在帖子的循环中。菜鸟失误!
    猜你喜欢
    • 2018-05-14
    • 1970-01-01
    • 2011-09-28
    • 2015-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-10
    • 2011-04-02
    相关资源
    最近更新 更多