Hello, I’ll paste the code for how I did it. You can see it here: https://www.webshowcase.tk/wp1
I did not use the same theme I created a child theme for the Twenty Thirteen theme. I hope it helps though.
I did it for my homepage so I have a file called index.php and between the loop I do get template part for a file I named content-home.php
Index.php:
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<ul id="og-grid" class="og-grid">
<?php if(is_home() || is_front_page()) {
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('showposts=12&paged='.$page.'&posts_per_page=10');
} ?>
<?php if (have_posts()) : ?>
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content-home', get_post_format() ); ?>
<?php endwhile; ?>
</ul>
<?php twentythirteen_paging_nav(); ?>
<script>
$(function() {
Grid.init();
});
</script>
<?php else : ?>
<?php get_template_part( 'content-home', 'none' ); ?>
<?php endif; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
The part you care about is the
ul tag
In content-home.php:
<?php
//Preview Size Image
if ( has_post_thumbnail() ) {
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'homepage-preview');
$url = $image_url[0];
}
else $url = get_bloginfo('stylesheet_directory').'/images/home-preview-default.jpg'
?>
<?php
//Thumb Size Image
if ( has_post_thumbnail() ) {
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'homepage-thumb');
$url2 = $image_url[0];
}
else $url2 = get_bloginfo('stylesheet_directory').'/images/home-thumb-default.jpg'
?>
<!---------------------Grid Posts---------------------->
<li class="invisible"><!--post-->
<a href= "<?php the_permalink() ?>" data-largesrc="<?php echo $url; ?>" data-title="<?php if (strlen($post->post_title) > 25) {
echo substr(the_title($before = '', $after = '', FALSE), 0, 25) . '...'; } else {
the_title();
} ?>" data-description="<?php echo get_excerpt(190); ?>"
>
<img src="<?php echo $url2; ?>" alt="<?php the_title(); ?>"/><span class="pstTitle"><h4><?php the_title(); ?></h4></span>
</a>
</li><!--end of post-->
For the second part I get the thumbnail image and the preview size image of the post or a default image in my images folder if no image exists for the post.