0

我正在使用WordPress的 nextgen 画廊插件。我正在制作一个页面,我想通过 id 获取 nextgen 画廊,并将其中的图像数量限制为 2。我用来获取画廊的代码是:

$post_id = get_the_ID();
$gallery = get_post_meta (get_the_ID(), 'Gallery', false);
$successes = $gallery[0]; /* Where $array is the variable holding the result */
$gallery_id= $successes[0];
echo do_shortcode('[nggallery id='.$gallery_id.']');

图库中有六张图片,它们在原始帖子中使用。这只是一个旅游帖子,所以我想限制这里的图片数量。这可能吗?

4

1 回答 1

0

您可以尝试以下短代码:

1.

echo do_shortcode("[nggallery id=$gallery_id images=2]");

images参数控制显示图像的数量。0表示全部显示。您还将获得一些分页链接来浏览画廊的图像。我还没有找到隐藏它们的选项,所以如果它们是不必要的,您可以通过 css ( display: none) 隐藏它们。

2.

echo do_shortcode("[random max=2 id=$gallery_id]");

从您的图库中随机显示最多 2 张图片。


我还推荐以下链接:

NextGEN Gallery 简码,var 2.0 及更高版本:http:
//www.nextgen-gallery.com/nextgen-gallery-shortcodes/

NextGEN 旧版简码:http:
//www.nextgen-gallery.com/help/shortcodes/

未记录的 NextGEN Gallery 简码:
http ://www.ralph-kemps.eu/2013/03/19/undocumented-nextgen-gallery-shortcodes/

于 2014-04-27T15:44:27.220 回答