Good Day. I am using a Gallery shortcode in my wordpress site to display images. Problem is that I wasnt the gallery to show only images from a certain category, for example category id 35. How do I specify it in the shortcode?
Shortcode:
[custom_gallery style="1" source="**cat=%cat_id%**" link="image" description="0" size="200x200" limit="10"]
Now I have tried the following, but does not work -
cat=%35%
cat=%cat_id=35%
Any suggestions? Thank you
SHORTCODE code:
/**
* Gallery posts shortcode
*/
function gallery_posts_func($atts, $content = null) {
extract(shortcode_atts(array(
"limit" => '5',
"cat" => '',
"thumb_width" => '',
"thumb_height" => '',
), $atts));
global $wp_query,$paged,$post;
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$query .= '&posts_per_page='.$limit;
$query .= '&post_type=gallery';
$query .= '&taxonomy=gallery_cat';
$query .= '&gallery_cat='.$cat;
$wp_query->query($query);
ob_start();
?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="gallery-holder fourthcol shortcode">
<?php
$gogo_gallery_video_url = get_post_meta($post->ID, 'gogo_gallery_video_url', true);
$gogo_gallery_links_to = get_post_meta($post->ID, 'gogo_gallery_links_to', true);
$gogo_gallery_title_links_to = get_post_meta($post->ID, 'gogo_gallery_title_links_to', true);
$gogo_gallery_custom_link = get_post_meta($post->ID, 'gogo_gallery_custom_link', true);
if ($gogo_gallery_title && $gogo_gallery_video_url && $gogo_gallery_title_links_to=="gallery_title_links_image") {
echo '<h5>';
echo '<a href="'.$gogo_gallery_video_url.'" rel="prettyPhoto[mixed]">';
echo ''.get_the_title().'';
echo '</a>';
echo '</h5>';
} elseif ($gogo_gallery_title && $gogo_gallery_title_links_to=="gallery_title_links_image") {
echo '<h5>';
echo '<a href="'.$thumbnail[0].'" rel="prettyPhoto[mixed]">';
echo ''.get_the_title().'';
echo '</a>';
echo '</h5>';
} elseif ($gogo_gallery_title && $gogo_gallery_title_links_to=="gallery_title_links_content") {
echo '<h5>';
echo '<a href="'.get_permalink().'">';
echo ''.get_the_title().'';
echo '</a>';
echo '</h5>';
} elseif ($gogo_gallery_title && $gogo_gallery_title_links_to=="gallery_title_links_link") {
echo '<h5>';
echo '<a href="'.$gogo_gallery_custom_link.'">';
echo ''.get_the_title().'';
echo '</a>';
echo '</h5>';
} elseif ($gogo_gallery_title) {
echo '<h5>';
echo ''.get_the_title().'';
echo '</h5>';
} else {
echo '';
}
?>
<div class="gallery-box">
<div class="gallery-image prettygallery">
<?php if (has_post_thumbnail()) { ?>
<?php
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
if ($gogo_gallery_video_url && $gogo_gallery_links_to=="gallery_links_image") {
echo '<a href="'.$gogo_gallery_video_url.'" rel="prettyPhoto[mixed]">';
echo '<img src="'.get_template_directory_uri().'/timthumb.php?src='.$thumbnail[0].'&w='.$thumb_width.'&h='.$thumb_height.'&zc=1&q=100&s=1" alt="'.get_the_title().'" />';
echo '</a>';
} elseif ($gogo_gallery_links_to=="gallery_links_image") {
echo '<a href="'.$thumbnail[0].'" rel="prettyPhoto[mixed]">';
echo '<img src="'.get_template_directory_uri().'/timthumb.php?src='.$thumbnail[0].'&w='.$thumb_width.'&h='.$thumb_height.'&zc=1&q=100&s=1" alt="'.get_the_title().'" />';
echo '</a>';
} elseif ($gogo_gallery_links_to=="gallery_links_content") {
echo '<a href="'.get_permalink().'">';
echo '<img src="'.get_template_directory_uri().'/timthumb.php?src='.$thumbnail[0].'&w='.$thumb_width.'&h='.$thumb_height.'&zc=1&q=100&s=1" alt="'.get_the_title().'" />';
echo '</a>';
} elseif ($gogo_gallery_links_to=="gallery_links_link") {
echo '<a href="'.$gogo_gallery_custom_link.'">';
echo '<img src="'.get_template_directory_uri().'/timthumb.php?src='.$thumbnail[0].'&w='.$thumb_width.'&h='.$thumb_height.'&zc=1&q=100&s=1" alt="'.get_the_title().'" />';
echo '</a>';
} else {
echo '<img src="'.get_template_directory_uri().'/timthumb.php?src='.$thumbnail[0].'&w='.$thumb_width.'&h='.$thumb_height.'&zc=1&q=100&s=1" alt="'.get_the_title().'" />';
}
?>
<?php } ?>
</div>
<?php if ($gogo_gallery_short_desc) { ?><em><?php echo $gogo_gallery_short_desc; ?></em><?php } ?>
</div>
</div>
<?php endwhile; ?>
<?php $wp_query = null; $wp_query = $temp;
$content = ob_get_contents();
ob_end_clean();
return $content;
}
add_shortcode("gallery_posts", "gallery_posts_func");