【问题标题】:Custom field to display custom image instead of featured image自定义字段以显示自定义图像而不是特色图像
【发布时间】:2013-08-16 17:14:54
【问题描述】:

我应该在 Wordpress 中使用什么自定义字段才能使用我的自定义图片而不是为帖子选择的“特色图片”?

此代码来自自定义页面模板,该模板用作博客首页并显示所有帖子:

<?php $thumb = '';
    $width = 184;
    $height = 184;
    $classtext = '';
        $titletext = get_the_title();

    $thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext);
    $thumb = $thumbnail["thumb"]; ?>

    <?php if ( $thumb <> '' && !$et_ptemplate_showthumb ) { ?>
    <div class="et_pt_thumb alignleft">
    <?php print_thumbnail($thumb, $thumbnail[""], $titletext, $width, $height, $classtext); ?>
    <a href="<?php the_permalink(); ?>"><span class="overlay"></span></a>
    </div> <!-- end .thumb -->
<?php }; ?>

【问题讨论】:

  • 很抱歉对您的其他问题如此严格。我绝对应该表现出更多的同情心。请不要太私人化。然而,考虑一些建议是个好主意。不管怎样,我只想说对不起。希望您解决了您的问题。

标签: wordpress


【解决方案1】:

您可以在 Custom Field 中添加图片 URL 或附件 ID,并使用函数 get_post_meta 获取值并在主题中打印图片。

但是,使用像Advanced Custom Fields 和它的Image Field 这样的插件会更容易。

【讨论】:

    猜你喜欢
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    • 1970-01-01
    • 2014-03-23
    • 1970-01-01
    • 2016-09-19
    • 2021-06-12
    相关资源
    最近更新 更多