获取链接到子页面的NextGen专辑的ID

时间:2014-11-27 作者:Squazz

我正在尝试查找与我所在的parrent页的子页链接的相册的相册ID。

假设我在“Youth”页面上,想要获取链接到子页面“galleries”(Youth->galleries)的相册的ID。如何在PHP中实现这一点?

我最终想要的是从那张专辑中获得画廊。我可以通过$nggdb->find\\u album($ID),然后通过$nggdb->find\\u gallery($galleryID)循环访问这些内容;但我首先还是需要得到这张专辑的ID。

1 个回复
最合适的回答,由SO网友:Squazz 整理而成

我得到了一些帮助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 :/\';
        }
    }
}
我希望这能帮助其他人,对我很有用:)

结束
获取链接到子页面的NextGen专辑的ID - 小码农CODE - 行之有效找到问题解决它

获取链接到子页面的NextGen专辑的ID

时间:2014-11-27 作者:Squazz

我正在尝试查找与我所在的parrent页的子页链接的相册的相册ID。

假设我在“Youth”页面上,想要获取链接到子页面“galleries”(Youth->galleries)的相册的ID。如何在PHP中实现这一点?

我最终想要的是从那张专辑中获得画廊。我可以通过$nggdb->find\\u album($ID),然后通过$nggdb->find\\u gallery($galleryID)循环访问这些内容;但我首先还是需要得到这张专辑的ID。

1 个回复
最合适的回答,由SO网友:Squazz 整理而成

我得到了一些帮助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 :/\';
        }
    }
}
我希望这能帮助其他人,对我很有用:)