Photo Gallery
- This topic has 1 reply, 2 voices, and was last updated 7 years, 1 month ago by
Grace Themes.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
July 24, 2017 at 1:04 pm #5139
Pradeep
ParticipantI 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?
July 24, 2017 at 4:16 pm #5145Grace Themes
MemberHi 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
Set filter=’false’ to remove the filter//[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' );
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.