如何修改以下脚本,以便显示来自创建的自定义字段的图像,而不是从默认的标头图像(由功能图像设置)中显示图像?我可以这样做并使它工作:($post->ID,'header-image',true)?
我尝试过设置一个名为header-image的自定义字段,但希望得到关于如何正确编写脚本的指导。
<?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]尝试修订
<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> 发布于 2017-05-14 06:23:38
您可以使用元() functio检索自定义字段中存储的值。
$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]https://stackoverflow.com/questions/43960884
复制相似问题