Skip to content

Instantly share code, notes, and snippets.

@simbasounds
Created January 10, 2016 15:53
Show Gist options
  • Save simbasounds/f6fe36f79eba1ade8f88 to your computer and use it in GitHub Desktop.
Save simbasounds/f6fe36f79eba1ade8f88 to your computer and use it in GitHub Desktop.
Single Custom Post Type Template for WordPress or WordPress + Genesis.
<?php
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'custom_loop' );
function custom_loop() {
while ( have_posts() ) : the_post();
if ( has_post_thumbnail() ) {
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail', true);
$my_thumb_url = $thumb_url[0];
$my_post_thumb = "background-image: url(" . $my_thumb_url .");";
} else {
$my_post_thumb = "background-image: url(my-default-logo-01.png);";
} ?>
<article class="post" itemscope="itemscope" itemtype="http://schema.org/BlogPosting" itemprop="blogPost">
<a class="post-image-link" href="<?php echo get_permalink(); ?>" style="<?php echo $my_post_thumb; ?>"></a>
<div class="entry-content">
<h2 class="entry-title" itemprop="headline">
<a href="<?php echo get_permalink(); ?>" title="<?php echo get_the_title(); ?>" rel="bookmark">
<?php echo get_the_title(); ?>
</a>
</h2>
<?php ob_wp_content(); ?>
</div>
</article>
<?php endwhile;
wp_reset_postdata();
}
genesis();
?>
@simbasounds
Copy link
Author

Makes use of the content with html tags function: https://gist.github.com/simbasounds/d96fde5967813fe4b9bf
Uses background image thumbnail (or default image if none is available). CSS will be required to make the thumbnail box visible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment