wordpress - Featured Image URL outside of Loop -
i have page on wordpress website called blog, set static page , blog page has list of blog posts. on blog page have featured image set. want use featured image background image on blog page.
home.php (template blog page):
at top of home.php before loop pulls list of blog posts have:
<?php $page_id = get_queried_object_id(); if ( has_post_thumbnail( $page_id ) ) : $image_array = wp_get_attachment_image_src( get_post_thumbnail_id( $page_id ), 'optional-size' ); $image = $image_array[0]; else : $image = get_template_directory_uri() . '/images/default-background.jpg'; endif; echo $image; ?> <div class="feature" style="background-image: url('<?php echo $image; ?>')"></div> this works , sets featured image. seems have set featured image on every single page on website featured image blog page. after changed featured image on page still pulls url blog page's featured image , sets featured image on page.
i have website here: http://www.cqwebdesign.co.uk/action-harpenden-physiotherapy/
as can see these screenshots have set different featured images on blog , page:
http://i.imgur.com/dnu8v9f.jpg
http://i.imgur.com/qshulwt.jpg
anyone know how can fix this?
as home.php template affects blog page, interesting how page.php template code looks (notice: page.php default template pages 'about' page) , why featured image isn't shown correctly on page(s).
try debug or echo id values blog page , page , verify if corresponding page id same 1 referred get_queried_object_id();.
i think you're having page.php template in case, if don't have 1 please notice wordpress' template hierarchy
wordpress codex: when static front page feature configured properly, wordpress not use custom page template display blog posts index, if custom page template assigned page designated "posts page". wordpress use either home.php or index.php.
Comments
Post a Comment