Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elihubogan/5433113 to your computer and use it in GitHub Desktop.
Save elihubogan/5433113 to your computer and use it in GitHub Desktop.
/* Post Thumbnail Grid */
.gridcontainer h2 a{color: #333; font-size: 13px;}
.gridcontainer .griditemleft{float: left; width: 150px; margin: 0 30px 20px 0;}
.gridcontainer .griditemright{float: left; width: 150px;}
.gridcontainer .postimage{margin: 0 0 5px 0;}
.gridcontainer .postimage-title {text-align: center;}
<?php
/*
Template Name: Thumbnails
*/
?>
<?php get_header(); ?>
<div class="gridcontainer">
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php
query_posts('posts_per_page=1000'); // Can also be limited to a specific category, like query_posts('cat=4&posts_per_page=1000');
$counter = 1; // Start the counter
$grids = 5; // Grids per row
$titlelength = 20; // Length of the post titles shown below the thumbnails
if(have_posts()) : while(have_posts()) : the_post();
// Show all columns except the right hand side column
if($counter != $grids) :
?>
<div class="griditemleft">
<div class="postimage">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a>
</div><!-- .postimage -->
<h2 class="postimage-title">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php if (mb_strlen($post->post_title) > $titlelength)
{ echo mb_substr(the_title($before = '', $after = '', FALSE), 0, $titlelength) . ' ...'; }
else { the_title(); } ?>
</a>
</h2>
</div><!-- .griditemleft -->
<?php
// Show the right hand side column
elseif($counter == $grids) :
?>
<div class="griditemright">
<div class="postimage">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a>
</div><!-- .postimage -->
<h2 class="postimage-title">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php if (mb_strlen($post->post_title) > $titlelength)
{ echo mb_substr(the_title($before = '', $after = '', FALSE), 0, $titlelength) . ' ...'; }
else { the_title(); } ?>
</a>
</h2>
</div><!-- .griditemright -->
<div class="clear"></div>
<?php
$counter = 0;
endif;
$counter++;
endwhile;
endif;
?>
</div><!-- .gridcontainer -->
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment