Jump to content

Featured image not showing on home.php


dpuk44

Recommended Posts

I cant work this one out for the life of me. The following code works great on my page.php, but cant get the same result on home.php

 



<!-- Main component for a primary marketing message or call to action -->

<?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>

<div class="jumbotron" style="background-image: url('<?php echo $feat_image; ?>');">
<div class="banner-box"><h1><?php $meta_value = get_post_meta( get_the_ID(), 'meta-text', true ); echo $meta_value; ?></h1></div>
</div>


 

 

Anyone?

Link to comment
https://forums.phpfreaks.com/topic/297262-featured-image-not-showing-on-homephp/
Share on other sites

Hi,

 

I have checked the source code and I can see the below. The URL seems empty as does the banner-box div which should pull in the data from the metabox.

<div class="jumbotron" style="background-image: url('');">
        <div class="banner-box"><h1></h1></div>
      </div>

Have you checked to see of $post->ID contains a value? How about get_the_ID(); does it return a value? Note that get_the_ID() needs to be called within The Loop. More information can be found here:

https://codex.wordpress.org/Function_Reference/get_the_ID

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.