Reply To: category specific gallery
January 14, 2018 at 6:06 am
#7382
Grace Themes
Member
Hi Giancarlo,
To show photo gallery of specific category in your page
Go to Appearance -> Editor -> custom-functions.php
add below new code at the end of custom-functions.php file
//[photogallery_cat]
function photogallery_cat_shortcode_func( $atts ) {
extract( shortcode_atts( array(
'show' => -1,
'category' => '',
), $atts ) );
$pfStr = '';
$pfStr .= '<div class="photobooth">';
$pfStr .= '<div class="row fourcol portfoliowrap"><div class="portfolio">';
$j=0;
//query_posts('post_type=photogallery&posts_per_page='.$show);
$args = array(
'post_type' => 'photogallery',
'posts_per_page' => $show,
'tax_query' => array(
array(
'taxonomy' => 'gallerycategory',
'field' => 'ID',
'terms' => $category
),
)
);
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->term_id;
}
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>
<h5>'.get_the_title().'</h5>
</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_cat', 'photogallery_cat_shortcode_func' );
Now use this short code to display images of specific category.
You need to change photo gallery category ID in (category=”3″)
[photogallery_cat category="3" show="10"]
Please check and let me know your feedback.
Regards
Grace Themes