Posting featured image to background with PHP?
-
Hi all,
I’m trying to get my WordPress posts to take the featured image (if there is one) and display it as an image across the top of the post, much like as done on https://www.medium.com.I’ve been searching and searching, and I found this piece of code:
<?php if(is_single() & !is_home()) { $myfield = 'header-image'; // Change this to the name of the custom field you use.. $postimage = get_post_meta($post->ID, $myfield, true); ?> <style type="text/css"> <!-- .header-image { border:none; color:black; <?php if($postimage) { // If the field has a value.. set background image using value... ?> background-image: url(<?php echo $postimage ?>); <?php } elseif(!$postimage) { // If no value ?> background-image: none; <?php } ?> } --> </style> <?php } ?>
but I can’t seem to get it to work. I’m not as familiar with PHP as I am with HTML and CSS, so if someone could help me make the link, I’d really appreciate it.
Good theme: https://devpress.com/themes/good/
Original thread: https://www.ads-software.com/support/topic/unique-header-image-for-each-post?replies=19
My site: stories.brianbennett.org
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Posting featured image to background with PHP?’ is closed to new replies.