Reputation: 51
I'd be really grateful if you could help with this.. I have a template that displays an image gallery for blog posts but I'd like to create another separate gallery to display the images from a custom post type that I have created called "kits". Which parts of this do I edit?
<?php /* Template Name: Top Kits */ ?>
<?php get_header(); ?>
<div id="main">
<?php do_action( 'bp_before_blog_page' ) ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2 class="post-title page-title"><?php the_title(); ?></h2>
<div class="post-content">
<?php the_content(); ?>
</div>
<?php endwhile; endif; ?>
<div class="image-gallery">
<?php
$total = $wpdb->get_var('SELECT count(p.id) FROM '.$wpdb->prefix.'posts p LEFT JOIN '.$wpdb->prefix.'postmeta pm ON p.id = pm.post_id WHERE p.post_status = \'publish\' AND post_type = \'post\' AND pm.meta_key = \'_thumbnail_id\'');
load_template( TEMPLATEPATH . '/functions/paginate.php' );
$pages = new paginate(array(
'total' => $total,
'nr_per_page' => of_get_option( 'gallery_count', 5 ) + 1
));
$thumbs = $wpdb->get_results('SELECT p.ID,p.post_title FROM '.$wpdb->prefix.'posts p LEFT JOIN '.$wpdb->prefix.'postmeta pm ON p.id = pm.post_id WHERE p.post_status = \'publish\' AND post_type = \'post\' AND pm.meta_key = \'_thumbnail_id\' ORDER BY p.post_date DESC LIMIT '.$pages->limit());
foreach ($thumbs as $thumb) : ?>
<div class="one_third">
<div class="post-img-medium">
<a href="<?php echo get_permalink($thumb->ID); ?>" rel="bookmark" title="<?php echo $thumb->post_title; ?>"><?php echo get_the_post_thumbnail($thumb->ID, 'post-medium'); ?></a>
</div>
</div>
<?php endforeach; ?>
<div class="clear"></div>
<div id="pagination">
<?php echo $pages->nav() ?>
</div>
</div>
</div><!--post-->
<?php do_action( 'bp_after_blog_page' ) ?>
</div><!--#main-->
<?php get_footer(); ?>
Upvotes: 2
Views: 631
Reputation: 5513
Use query_posts:
<?php query_posts(array('post_type' => 'kits', 'posts_per_page' => -1 ))
if (have_posts()) : while (have_posts()) : the_post(); ?>
More info here: http://codex.wordpress.org/Function_Reference/query_posts
Upvotes: 3