• Resolved imanc

    (@imanc)


    Hi,
    I need to access photos in a gallery from php code.
    I found the following solution:

    <?php 
    
    require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
    
      $gallery_id = 1;
      $imagegallery = new nggdb();
      $images = $imagegallery->get_gallery(1);

    Is it correct? I see that the nggdb class is in the legacy folder, is there a new mode to get the job done?
    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor photocrati

    (@photocrati)

    @imanc – This snippet, in general, should help to get you the references you may need:

    $gallery_id     = 3; // for example
    $gallery_mapper = C_Gallery_Mapper::get_instance();
    $image_mapper   = C_Image_Mapper::get_instance();
    $storage        = C_Gallery_Storage::get_instance();
    $gallery        = $gallery_mapper->find($gallery_id);
    $image          = $image_mapper->find($gallery->previewpic);
    var_dump($image);
    var_dump($storage->get_image_url($image, 'thumb'));
    var_dump($storage->get_image_url($image, 'full'));

    Thanks!

    – Cais.

    Thread Starter imanc

    (@imanc)

    Thank you, now I understand how the plugin works. As reference, with the following code I get all images of the gallery with id=1

    $gallery_id     = 1;
    $gallery_mapper = C_Gallery_Mapper::get_instance();
    $gallery        = $gallery_mapper->find($gallery_id, TRUE);
    
    var_dump($gallery->get_images());
    
    • This reply was modified 9 years, 2 months ago by imanc.
    • This reply was modified 9 years, 2 months ago by imanc.
    Plugin Contributor photocrati

    (@photocrati)

    @imanc – Thanks for sharing!

    – Cais.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Access nextgen galleries from php code’ is closed to new replies.