Forums

PopupGallery hack /using the post ID out of loop (2 posts)

  1. baxter13
    Member
    Posted 5 years ago #

    I'm trying to modify a bit of the code on the PopupGallery 4.2.2 so that the gallery index images show up on the correct parent pages. (My image pages are nested so that there's a main Images page and then several subImages pages.)

    I've been modifying the fgtags.php file in order to this but my problem is I can't find a way to call up the current page's ID in a variable I've called $pageid(I'm a persistent newbie to PHP). Right now, I just have it set to $pageid = 27, which is the page ID for one of the nested pages.

    Here's what I have set up.

    function fg_gallery_index($image_class='gallerythumb', $index_style='table', $show=true)
    {
    global $table_prefix, $wpdb;
    $pageid = 27; //the code here should retrieve the current page's ID but I can't get anything to work

    //now load the collection records
    // changed to order the gallery by the parent pages and then by the post title
    // the where statement limits the index images to the ones whose parent page is the current page
    $fg_imagedata = $wpdb->get_results('SELECT ' . $table_prefix . 'gallerypage.ID, ' . $table_prefix . 'gallerypage.gallerypath, ' . $table_prefix . 'gallerypage.indextext, ' . $table_prefix . 'gallerycollection.thumbfile, ' . $table_prefix . 'posts.post_title
    FROM ' . $table_prefix . 'gallerypage
    LEFT JOIN ' . $table_prefix . 'posts ON ' . $table_prefix . 'gallerypage.ID = ' . $table_prefix . 'posts.ID
    LEFT JOIN ' . $table_prefix . 'gallerycollection ON ' . $table_prefix . 'gallerypage.ID = ' . $table_prefix . 'gallerycollection.ID WHERE ' . $table_prefix . 'gallerycollection.indexfile = 1 AND ' . $table_prefix . 'posts.post_parent = ' . $pageid . '
    ORDER BY ' . $table_prefix . 'posts.post_parent, ' . $table_prefix . 'posts.post_title;');

    // the following lines are unchanged

    Also, I'd like to add a piece of code (an OR statement in the WHERE condition?) that makes it so if you're on the main page (post_parent of that page would be 0 (zero) and none of the gallery index image's posts.post_parent variable would match that page) all of the photos in the index show up. This would happen on the main "Images" page.

  2. baxter13
    Member
    Posted 5 years ago #

    I've figured out the variable for the page ID.

    global $wp_query;
    $pageid = $wp_query->post->ID;

    If anyone else is trying something similar, here is the functional code, thanks to help from Andy Stains at Yellowswordfish.com (PopupGallery creator).

    If anyone has ideas on how to add headings for each category of parent page on the main Index page, that would be great. I'll post if I find a solution.


    // tag: fg_gallery_index - place an index of links somewhere (i.e. sidebar) - also called from Page tag 'galleryindex'
    // -------------------------------------------------------------------------------------------------------------------

    function fg_gallery_index($image_class='gallerythumb', $index_style='table', $show=true)
    {
    global $table_prefix, $wpdb, $wp_query;
    $pageid = $wp_query->post->ID;// the code here should retrieve the current page's ID
    $parentid = $wp_query->post->post_parent;
    // determine the parent page ID

    //now load the collection records
    // changed to order the gallery by the parent pages and then by the post title
    // the where statement limits the index images to the ones whose parent page is the current page
    $fg_imagedata = $wpdb->get_results('SELECT ' . $table_prefix . 'gallerypage.ID, ' . $table_prefix . 'gallerypage.gallerypath, ' . $table_prefix . 'gallerypage.indextext, ' . $table_prefix . 'gallerycollection.thumbfile, ' . $table_prefix . 'posts.post_title
    FROM ' . $table_prefix . 'gallerypage
    LEFT JOIN ' . $table_prefix . 'posts ON ' . $table_prefix . 'gallerypage.ID = ' . $table_prefix . 'posts.ID
    LEFT JOIN ' . $table_prefix . 'gallerycollection ON ' . $table_prefix . 'gallerypage.ID = ' . $table_prefix . 'gallerycollection.ID
    WHERE ' . $table_prefix . 'gallerycollection.indexfile = 1 AND ' . $table_prefix . 'posts.post_parent = ' . $pageid . ' OR ' . $table_prefix . 'gallerycollection.indexfile = 1 AND ' . $parentid . ' = 0
    ORDER BY ' . $table_prefix . 'posts.post_parent, ' . $table_prefix . 'posts.post_title;');

Topic Closed

This topic has been closed to new replies.

About this Topic