Viewing 4 replies - 1 through 4 (of 4 total)
  • Benjamin

    (@benjaminowens)

    Hi Squazz, I hope I’m interpreting your question correctly.

    To do this I believe you will need to know the ID of the page that has been linked to by your album(s):

    $page_id = 776;
    $album_mapper = C_Album_Mapper::get_instance();
    $albums = $album_mapper->find_all(array('pageid = %s', $page_id), TRUE);
    foreach ($albums as $album) {
      $galleries = $album->get_galleries(TRUE);
      // $album may also be inspected through var_dump($album->get_entity())
      foreach ($galleries as $gallery) {
        // $gallery may also be inspected through var_dump($gallery->get_entity());
        // retrieve images belonging to this gallery
        var_dump($gallery->get_images());
      }
    }

    I hope that helps!

    Thread Starter Squazz

    (@squazz)

    Thank you very much Benjamin. It helped me a lot! ??

    This is the code I ended up with (kindly modified to help others in the future).
    The code includes my personal preference for styling the galleries.

    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();
    
            $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 :/';
            }
        }
    }
    Plugin Contributor photocrati

    (@photocrati)

    @squazz – Thanks for sharing!!

    – Cais.

    Thread Starter Squazz

    (@squazz)

    @photocrati – No probs, I hope it’s something that’s usefull ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get ID of the album that is linked to a subpage’ is closed to new replies.