Skip to content

Instantly share code, notes, and snippets.

@avantegarde
Last active August 29, 2015 14:23
Show Gist options
  • Save avantegarde/a41233623c2347e0d90f to your computer and use it in GitHub Desktop.
Save avantegarde/a41233623c2347e0d90f to your computer and use it in GitHub Desktop.
Single Post Template with 2 featured image options.
<?php
/**
* The template for displaying all single posts.
*
* @package theme_name
*/
get_header(); ?>
<!-- Option #1 - Default way of calling the "Full" Featured image size and placing it inside a div that would be 100% wide on screen. -->
<?php if ( has_post_thumbnail() ): ?>
<div class="full-width-div">
<?php the_post_thumbnail('full'); ?>
</div>
<?php endif; ?>
<!-- END Option #1 -->
<!-- Option #2 - Get post thumbnail image src and apply it as a css background image to the div. This requires a height/min-height on the div if it is empty. -->
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-image' ); ?>
<div class="full-width-div" style="min-height: 200px; background-image: url('<?php echo $image[0]; ?>')"></div>
<?php endif; ?>
<!-- END Option #2 -->
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'template-parts/content', 'single' ); ?>
<?php the_post_navigation(); ?>
<?php
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
<?php endwhile; // End of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment