首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从自定义字段获取图像,而不是默认的标头图像(特征图像)

从自定义字段获取图像,而不是默认的标头图像(特征图像)
EN

Stack Overflow用户
提问于 2017-05-14 06:10:08
回答 1查看 45关注 0票数 0

如何修改以下脚本,以便显示来自创建的自定义字段的图像,而不是从默认的标头图像(由功能图像设置)中显示图像?我可以这样做并使它工作:($post->ID,'header-image',true)?

我尝试过设置一个名为header-image的自定义字段,但希望得到关于如何正确编写脚本的指导。

代码语言:javascript
复制
<?php
if ( has_post_thumbnail() && ! post_password_required() ) :
    $featuredimage = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'resonar-large' );
?>
<div class="entry-header-background" style="background-image:url(<?php echo esc_url( $featuredimage[0]

尝试修订

代码语言:javascript
复制
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
 <?php
    if ( has_post_thumbnail() && ! post_password_required() ) :
$custom_field = get_post_meta($post_id, 'header-image', true);
?>
<div class="entry-header-background" style="">
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img  src="http://www.example.com/images/<?php echo get_post_meta($post- >ID, 'header-image', true); ?>" alt="Icon for Post #<?php the_ID(); ?>" /></a> 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-14 06:23:38

您可以使用元() functio检索自定义字段中存储的值。

代码语言:javascript
复制
$custom_field = get_post_meta($post_id, 'header-image', true);
?>
<div class="entry-header-background" style="background-image:url(<?php echo esc_url( $custom_field [0]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43960884

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档