Support » Themes and Templates » Filter gallery by category

Filter gallery by category

  • I am trying to modify the template which comes with a gallery feature. I would like to create a site with three gallery pages. Each gallery would feature images using a specific category. I am assuming I will need to create different templates for each page and modify each somehow to filter out only the appropriate category.

    I am including a copy of the template below. I thought I would just need to edit the line 'post_type' => $type to read 'post_type' => 'category1' but that doesn’t seem to work.

    Any ideas how I could do this?

    Template Name: Gallery
    if(!empty($data['aq_gallery_layout'])) :  $column = strtolower($data['aq_gallery_layout']); else : $column = 'items-4-col'; endif;
    get_header(); ?>
    		<div id="content-gallery" class="cf">
                <div class="the-top">
                   	<div class="the-title"><h1><?php the_title(); ?></h1></div>
    				<ul class="items <?php echo $column; ?>">
    				$size = aq_get_items_column_size($column);
    				$title_limit = 40; //gallery title characters limit
    				if(!empty($data['gallery_title_limit'])) {
    					$title_limit = (int) $data['gallery_title_limit'];
    				$excerpt_limit = 10; //gallery excerpt words limit
    				if(!empty($data['gallery_excerpt_limit'])) {
    					$excerpt_limit = (int) $data['gallery_excerpt_limit'];
    				$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                    $count = 1;
            	    $type = 'gallery';
    					'post_type' => $type,
    					'paged' => $paged,
    					'posts_per_page' => $data['gallery_count'],
    				$temp = $wp_query;  // assign original query to temp variable for later use
    				$wp_query = null;
    				$wp_query = new WP_Query();
    					if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post();
    					$custom_thumbnail =''; //initialize variables
    					$custom_thumbnail = get_post_meta(get_the_ID(), 'aq_custom_thumbnail', TRUE);
    					if(!empty($custom_thumbnail)) {
    						$thumb = get_attachment_id_from_src($custom_thumbnail);
    						if(empty($thumb)) {$thumb = '';}
    						$image = vt_resize( $thumb, '', $size['img_width'], $size['img_height'], true );
    						$image_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
    						$image_url = $image_src [0];
    					} elseif (has_post_thumbnail()) {
    						$thumb = get_post_thumbnail_id();
    						$image = vt_resize( $thumb, '', $size['img_width'], $size['img_height'], true );
    						$image_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
    						$image_url = $image_src [0];
    					<li class="item">
                            <div id="gallery-<?php the_ID(); ?>" <?php post_class(); ?>>
    							<?php if (has_post_thumbnail()) { ?>
    							<div class="post-thumb-wrap image-wrap-out radius3">
    								<div class="post-thumb image-wrap-in radius3">
    								<a href="<?php the_permalink(); ?>">
    									<img src="<?php echo $image['url']; ?>" alt="<?php the_title(); ?>" width="<?php echo $size['img_width'];?>" height="<?php echo $size['img_height'];?>"/>
    							<?php } ?>
    							<div class="the-title">
    								<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo shortentext(get_the_title(), $title_limit ); ?></a></h2>
    							<div class="the-excerpt">
    								<p><?php aq_excerpt($excerpt_limit); ?></p>
    					<?php $count++; endwhile; endif; wp_reset_query();?>
    				</ul><!--End .items-->
    			<div id="aqua-pagination">
    			<?php if (function_exists("pagination")) { pagination(); } ?>
    		</div><!--End #content-gallery-->
    	</div><!--End #main-container-->
    <?php get_footer(); ?>
  • The topic ‘Filter gallery by category’ is closed to new replies.
Skip to toolbar