我得到了一些帮助Benjamin at the Wordpress support forums
我最终得到的解决方案如下:
global $nggdb;
$galleries = array();
$children = get_children("post_parent=$post->ID");
foreach($children as $kid) {
print_r($kid);
$page_id = $kid->ID;
$album_mapper = C_Album_Mapper::get_instance();
$albums = $album_mapper->find_all(array(\'pageid = %s\', $page_id), TRUE);
foreach ($albums as $albumMap) {
$albumID = $albumMap->ID();
找到相册ID后,我开始查找此相册中的图库
$album = $nggdb->find_album($albumID);
if($album) {
foreach( $album->gallery_ids as $galleryid ){
$gallery = $nggdb->find_gallery($galleryid);
$image = $nggdb->find_image( $gallery->previewpic );
$galleries[$galleryid][\'title\'] = $gallery->title;
$galleries[$galleryid][\'url\'] = home_url() . $post->post_name . \'/\' . $kid->post_name . \'/?album=all&gallery=\' . $galleryid;
$galleries[$galleryid][\'image\'] = ($image->thumbURL) ? \'<img src="\' . $image->thumbURL . \'" />\' : \'\';
}
$i = 1;
foreach($galleries as $category){
echo \'<div class="galleryContainer">\'
. \'<a href="\' . $category[\'url\'] . \'" class="galleryImage">\'
. $category[\'image\']
. \'<div class="galleryTitle">\'
. $category[\'title\']
. \'</div>\'
. \'</a>\'
. \'</div>\';
if ($i++ == 3) break;
}
} else {
echo \'No galleries at this time, sorry :/\';
}
}
}
我希望这能帮助其他人,对我很有用:)