Featured Images as Background on Posts page
-
I’m using a custom theme, it’s a child theme of Twenty Thirteen.
I am trying to pull in the post’s featured image as the background image for a <div> on the post page, for each post. (Where the list of blog posts are).
Here is the
content-link.php
page that is creating the list of posts.<?php /** * The template for displaying posts in the Link post format * * @package WordPress * @subpackage Twenty_Thirteen * @since Twenty Thirteen 1.0 */ ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?> style="border: none;"> <div class="entry-content"> <header class="entry-header"> <h1 class="entry-title"> <a href="<?php echo esc_url( twentythirteen_get_link_url() ); ?>"><?php the_title(); ?></a> </h1> <div class="entry-meta"> <?php twentythirteen_entry_date(); ?> <?php edit_post_link( __( 'Edit', 'twentythirteen' ), '<span class="edit-link">', '</span>' ); ?> </div><!-- .entry-meta --> </header><!-- .entry-header --> <?php if ( has_post_thumbnail() && ! post_password_required() ) : ?> <?php $imgID = get_post_thumbnail_id($post->ID); //get the id of the featured image $featuredImage = wp_get_attachment_image_src($imgID, 'full' );//get the url of the featured image (returns an array) $imgURL = $featuredImage[0]; //get the url of the image out of the array ?> <div class="entry-thumbnail"> <div id="cropped" style="background:url(<?php echo $imgURL ?>);"></div> </div> <?php endif; ?> <?php if ( has_excerpt() ) : ?> <div class="entry-summary"> <?php the_excerpt(); ?> </div><!-- .entry-summary --> <?php endif; ?> <? /*<div class="entry-content"> <?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentythirteen' ) ); ?> <?php wp_link_pages( array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?> </div><!-- .entry-content --> */ ?> <?php if ( is_single() ) : ?> <footer class="entry-meta"> <?php twentythirteen_entry_meta(); ?> <?php if ( get_the_author_meta( 'description' ) && is_multi_author() ) : ?> <?php get_template_part( 'author-bio' ); ?> <?php endif; ?> </footer><!-- .entry-meta --> </div> <?php endif; // is_single() ?> </article><!-- #post -->
It doesn’t seem like the
<?php if ( has_post_thumbnail() && ! post_password_required() ) : ?>
is working correctly.<div class="entry-thumbnail"> <div id="cropped" style="background:url(<?php echo $imgURL ?>);"></div> </div>
Is getting pulled in even if the post doesn’t have a featured image attached to it.
Any help would be appreciated. Thank you.
https://theromanguy.com/dev/blog/ (the page in question)
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Featured Images as Background on Posts page’ is closed to new replies.