Get 20% Off On All Our Premium WordPress Themes Bundle. Use GRACEBFCM Coupon Code For Discount Deal Upto Dec 15 Buy Now

Photo Gallery Shortcode display Category

Home Support Power Club WordPress Theme Photo Gallery Shortcode display Category

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

    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?

    regards
    Sam P

    #4293
    Grace Themes
    Member

    Hi

    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?

    Regards
    Grace Themes

    #5138
    Pradeep
    Participant

    Hi Sam P,

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

    #5143
    Grace Themes
    Member

    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

    /[photogallery_category]
    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">';
    	$j=0;
    	
    	$args = array( 
    				'post_type' => 'photogallery', 
    				'posts_per_page' => $show, 
    				'tax_query' => array(
    					array(
    						'taxonomy' => 'gallerycategory',
    						'field' => 'ID',
    						'terms' => $categoryArray,
    						'operator' => 'IN'
    					),
    				)
    				
    			);
    	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( 'photogallery_category', 'photogallery_shortcode_category_func' );

    Regards
    Grace Themes

    • This reply was modified 3 years, 4 months ago by Grace Themes.
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.