Photo Gallery Shortcode display Category
- This topic has 3 replies, 3 voices, and was last updated 7 years, 4 months ago by Grace Themes.
-
AuthorPosts
-
April 30, 2017 at 11:24 am #4289SamParticipant
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 PApril 30, 2017 at 1:06 pm #4293Grace ThemesMemberHi
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 [email protected] so we can make changes in your site to display categorized photo gallery?
Regards
Grace ThemesJuly 24, 2017 at 1:02 pm #5138PradeepParticipantHi Sam P,
i need same feature which you needed. please help me in showing only selected categorys in the photo gallery.
July 24, 2017 at 4:10 pm #5143Grace ThemesMemberHi 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 -
AuthorPosts
- You must be logged in to reply to this topic.