再会。我在我的 wordpress 网站中使用图库短代码来显示图像。问题是我不是画廊只显示某个类别的图像,例如类别 id 35。我如何在短代码中指定它?
短代码:
[custom_gallery style="1" source="**cat=%cat_id%**" link="image" description="0" size="200x200" limit="10"]
现在我尝试了以下方法,但不起作用 -
cat=%35%
cat=%cat_id=35%
简码(因为它是自定义简码):
/**
* 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");