support@gracethemes.com

Reply To: Personalize PhotoGallery

Home Support ZeroError WordPress Theme Personalize PhotoGallery Reply To: Personalize PhotoGallery

#2995

Grace Themes
Keymaster

Hi Gnanadoss,

To display Photo Galley for single category use below code at the end of custom_function.php file

And use this shortcode
[photo-category category_id=”9″ show=”20″]
(change the category id to show images of that category)

//Photo Galley for single category: [photo-category category_id="5" show="20"]
function photo_category_shortcode_func( $atts ) {
	extract( shortcode_atts( array(
		'show' => '',
		'category_id' => '',
		'filter' => 'false'
	), $atts ) );
	$pfStr = '';

	$pfStr .= '<div class="photobooth">';

	$pfStr .= '<div class="row fivecol portfoliowrap"><div class="portfolio">';
	$j=0;
	$args = array( 
				'post_type' => 'photogallery', 
				'order' => 'asc',
				'posts_per_page' => -1,
				'tax_query' => array(
					array(
						'taxonomy' => 'gallerycategory',
						'field' => 'ID',
						'terms' => $category_id
					),
				)
				
			);
	query_posts( $args );
	if ( have_posts() ) : while ( have_posts() ) : the_post(); 
	$j++;
		$videoUrl = get_post_meta( get_the_ID(), 'video_file_url', true);
		$imgSrc = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
		$terms = wp_get_post_terms( get_the_ID(), 'gallerycategory', array("fields" => "all"));
		$slugAr = array();
		foreach( $terms as $tv ){
			$slugAr[] = $tv->slug;
		}
		if ( $imgSrc[0]!='' ) {
			$imgUrl = $imgSrc[0];
		}else{
			$imgUrl = get_template_directory_uri().'/images/img_404.png';
		}
		$pfStr .= '<div class="entry '.implode(' ', $slugAr).'"><div class="holderwrap">
					 <a href="'.( ($videoUrl) ? $videoUrl : $imgSrc[0] ).'" data-rel="prettyPhoto[bkpGallery]"><img src="'.$imgSrc[0].'"/></a>
            </div></div>';
		unset( $slugAr );
	endwhile; else: 
		$pfStr .= '<p>Sorry, photo gallery is empty.</p>';
	endif; 
	wp_reset_query();
	$pfStr .= '</div></div>';
	$pfStr .= '</div>';
	return $pfStr;
}
add_shortcode( 'photo-category', 'photo_category_shortcode_func' );