好的,我在网上找到了这段代码,它允许您添加要在gallery快捷码中显示多少缩略图的选项。
下面的代码是他们所说的要添加到函数中的代码。php文件
function get_random_gallery_images(){
global $wpdb,$post;
$ids = "";
$counter = 0;
$number_of_posts = 4;
$args = array(
\'post_type\' => \'attachment\',
\'numberposts\' => 4,
\'post_status\' => null,
\'orderby\' => \'rand\',
\'post_parent\' => $post->ID
);
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $attachment) {
if ($counter != 0) {
$ids .= \',\'.$attachment->ID;
}
else {
$ids .= $attachment->ID;
}
$counter++;
}
}
return $ids; }
然后他们说将下面的代码添加到循环中 $attachment_ids = get_random_gallery_images();
echo do_shortcode(\'[ gallery columns="4" include="\'.$attachment_ids.\'" link="file" ]\');
但我的问题是,他们没有说在循环中的何处添加代码。有人知道我可以在哪里添加此代码吗?此外,如果您有更好的解决方案来实现我的要求,请分享:)