【问题标题】:wordpress child theme twentyeleven showing featured imageswordpress 儿童主题 211 显示特色图片
【发布时间】:2013-06-07 11:58:01
【问题描述】:

我正在尝试用 211 制作一个儿童主题,到目前为止,就 css 而言一切都很好,但现在我想显示一张特色图片,但我不知道如何。

我将此添加到我的functions.php;

// add featured images 
add_theme_support('post-thumbnails');
set_post_thumbnail_size(500, 200);

这意味着特色图片已启用,但仍不会显示。我在其他预制布局中使用了特色图像,所以我知道就设置图像而言我没有做错任何事情。我想我必须在我的 single.php 文件或者我的 post.php 文件中添加一些代码?我找到了这段代码;

if (has_post_thumbnail()) {
    the_post_thumbnail();
}

并放入我的子主题的(空)single.php 文件,但它不起作用。我需要什么代码,我需要把它放在哪里来显示这些特色图片?

【问题讨论】:

    标签: php wordpress themes wordpress-theming featured


    【解决方案1】:
    <?php echo get_the_post_thumbnail($post_id, 'large', array('class' => 'class_here')); ?>
    

    或者如果您想链接到其他尺寸:

    <?php 
    if ( has_post_thumbnail()) {
        $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
        echo '<a href="' . $large_image_url[0] . '" title="' . the_title_attribute('echo=0') . '" class="classes_here" >';
        the_post_thumbnail('large');
        echo '</a>';
    }
    ?>
    

    More in codex WP

    希望对你有帮助

    /保罗

    【讨论】:

    • 我将您的第一个代码添加到 content.php,将 class_here 替换为后期缩略图,但仍然没有显示。
    • 您是否在外观上激活了子主题并上传了特色图片?什么是 content.php,因为它不是 wp 模板文件。
    • 另外...二十一具有对 post_thumbnails 的主题支持,因此您不必将 add_theme_support.... 放在您的 function.php 文件中。在我的脑海中,twenty11 的 single.php 没有帖子缩略图,但是当您使用 2011 的 content-single.php 并将缩略图代码放在那里时,循环中的某个位置。 content-single.php 包含在 single.php 中,带有 get_template_part....
    • 谢谢你,保罗,我会研究你给我的建议。周末愉快:)
    • 很遗憾没有......明天我可以将所有内容导出到我的服务器,以便向您展示实际的代码和问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-06
    • 2013-12-03
    • 2017-06-06
    • 2014-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多