Skip to content

Instantly share code, notes, and snippets.

@kaskajp
Created March 17, 2015 12:17
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 kaskajp/91cf4bacfa601efae5b4 to your computer and use it in GitHub Desktop.
Save kaskajp/91cf4bacfa601efae5b4 to your computer and use it in GitHub Desktop.
Custom Post Type Loop
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array(
'post_type' => 'myposttype',
'posts_per_page' => 10,
'paged' => $paged)
);
?>
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php $thumb = get_the_post_thumbnail($post->ID, 'md4'); ?>
<?php if($thumb): ?>
<a href="<?php the_permalink(); ?>"><?php echo $thumb; ?></a>
<?php else: ?>
<a href="<?php the_permalink(); ?>"><img src="http://placehold.it/287x196" alt="" /></a>
<?php endif; ?>
<h1><?php the_title(); ?></h1>
<?php endwhile; ?>
<?php
// Add pagination here
// E.g.
// if(function_exists('wp_paginate')) {
// wp_paginate();
// }
?>
<?php else: ?>
<p>No posts found.</p>
<?php endif; ?>
<?php wp_reset_query(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment