Happy New Year Sale: 10% off on Themes Bundle, use coupon code "grace2019" Buy Now

Photo Gallery Shortcode display Category

Home Support Power Club WordPress Theme Photo Gallery Shortcode display Category

This topic contains 3 replies, has 3 voices, and was last updated by  Grace Themes 1 year, 6 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #4289


    I want to show a photo gallery on a page and shortcode works fine but how do I display a selected category instead of showing all images with filters?

    Sam P


    Grace Themes


    To display photo gallery from selected category, needs to make some changes in custom-functions.php file.

    Can you please send your website URL and WordPress admin login details for temporary at support@gracethemes.com so we can make changes in your site to display categorized photo gallery?

    Grace Themes



    Hi Sam P,

    i need same feature which you needed. please help me in showing only selected categorys in the photo gallery.


    Grace Themes

    Hi Pradeep,

    I have completed the changes in custom-functions.php file of your website to display categorized photo gallery.

    I have added below code in inc/custom-functions.php file

    For customized photo gallery use shortcode:
    [photogallery_category filter=’true’ category_id=’5,6′]

    You just need to change the category_id

    function photogallery_shortcode_category_func( $atts ) {
    	extract( shortcode_atts( array(
    		'show' => -1,
    		'category_id' => '',
    		'filter' => 'true'
    	), $atts ) );
    	$pfStr = '';
    	$categoryArray = explode(',', $category_id);
    	$pfStr .= '<div class="photobooth">';
    	if( $filter == 'true' ){
    		$pfStr .= '<div class="filter-gallery"><ul class="portfoliofilter clearfix"><li><a class="selected" data-filter="*" href="#">'.of_get_option('galleryshowallbtn').'</a><span></span></li>';
    		$args = array( 'include' => $categoryArray );
    		$categories = get_terms( 'gallerycategory', $args );
    		foreach ($categories as $category) {
    			$pfStr .= '<li><a data-filter=".'.$category->slug.'" href="#">'.$category->name.'</a></li>';
    		$pfStr .= '</ul></div><div class="clear"></div>';
    	$pfStr .= '<div class="row fivecol portfoliowrap"><div class="portfolio">';
    	$args = array( 
    				'post_type' => 'photogallery', 
    				'posts_per_page' => $show, 
    				'tax_query' => array(
    						'taxonomy' => 'gallerycategory',
    						'field' => 'ID',
    						'terms' => $categoryArray,
    						'operator' => 'IN'
    	query_posts( $args );
    	if ( have_posts() ) : while ( have_posts() ) : the_post(); 
    		$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];
    			$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>
    		unset( $slugAr );
    	endwhile; else: 
    		$pfStr .= '<p>Sorry, photo gallery is empty.</p>';
    	$pfStr .= '</div></div>';
    	$pfStr .= '</div>';
    	return $pfStr;
    add_shortcode( 'photogallery_category', 'photogallery_shortcode_category_func' );

    Grace Themes

    • This reply was modified 1 year, 6 months ago by  Grace Themes.
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.