Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Stason4ik1986/f4c68cea4f43d078ed6b to your computer and use it in GitHub Desktop.

Select an option

Save Stason4ik1986/f4c68cea4f43d078ed6b to your computer and use it in GitHub Desktop.
WordPress use post thumbnail as div background
<?php if ( have_posts() ) : query_posts('p=1');
while (have_posts()) : the_post(); ?>
<div <?php
if ( $thumbnail_id = get_post_thumbnail_id() ) {
if ( $image_src = wp_get_attachment_image_src( $thumbnail_id, 'normal-bg' ) )
printf( ' style="background-image: url(%s);"', $image_src[0] );
}?> ></div>
<?php endwhile; endif; wp_reset_query(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment