WordPress.org

Ready to get started?Download WordPress

Forums

Gallery
[resolved] Albums and Sub Albums (18 posts)

  1. itissue
    Member
    Posted 9 months ago #

    Is there a way to have sub albums be listed in a parent album and only display parent albums on the gallery page until the user selects the parent album they want to view? Then the sub albums will display within that parent album?

    For instance:

    Parent album 1 | Parent album 2 | Parent album 3

    Parent album 1 has the following:
    Sub album 1 | Sub album 2 | Sub album 3 | Sub album 4

    Parent album 2 has different sub albums, and Parent album 3 has different sub albums. Each sub album has images.

    Best,
    Sue

    http://wordpress.org/plugins/gallery-plugin/

  2. kchayka
    Member
    Posted 9 months ago #

    I am interested in this, too.

  3. itissue
    Member
    Posted 9 months ago #

    I know there's a way to create pages manually and put each album on the page every time a new album is created. In that way, don't pick the gallery template for the page. But is there an automatic way, since you are already given the option of making sub albums in choosing if the album has a parent and what that parent is.

  4. kchayka
    Member
    Posted 9 months ago #

    itissue, if you're going to make up a separate page for each gallery (parents and children), you might as well just use the in-built WP gallery instead. Part of the point of using a plugin is to automate gallery generation. ;)

    While the Gallery plugin does support parent/child relationships, it does not separate them on the main gallery page. When I added a child gallery it just added it to the main gallery page along with the parent, instead of showing the child only on the parent's page. The child doesn't show on the parent's page at all, but this what it logically should do.

  5. itissue
    Member
    Posted 9 months ago #

    Thanks kchayka.

    Well, this is what I ended up doing. I created a page called Projects and put the shortcode for each parent album there. Then for the gallery, I had parent and children albums. The parent albums have each of the children albums shortcode listed in them. I made some modifications to the template and styles to suit my needs.

    Projects page:
    https://www.diigo.com/item/image/4anod/29qn

    Parent album example:
    https://www.diigo.com/item/image/4anod/qbs0

    Child album example:
    https://www.diigo.com/item/image/4anod/ua4d

  6. itissue
    Member
    Posted 9 months ago #

    I forgot to explain this:

    The projects page lists the types of projects. Then when you click on a project type, it lists the different projects in that project type. Then you click on a project to view individual images and a short desription about that project. Clicking on those images then triggers fancybox.

  7. kchayka
    Member
    Posted 9 months ago #

    I can see how this functions, but it's a lot of extra work if you have many galleries.

  8. itissue
    Member
    Posted 9 months ago #

    Is there a better solution? That's what I was trying to look for, but I couldn't find it, so that's why I am stuck with this solution.

  9. itissue
    Member
    Posted 9 months ago #

    I may think about this more. There has to be a better way. Meanwhile, if someone else has a better idea, please feel free to chime in. Thanks!

  10. kchayka
    Member
    Posted 9 months ago #

    IMO it's something the plugin should already be doing. It's not on the list of features for the Pro version, either. It would be nice for the plugin author to respond to this...

  11. itissue
    Member
    Posted 9 months ago #

    I thought of an idea, but haven't gotten it to work, though it should work in theory. I created a query string called cat and when it's "residential", then the gallery template will filter "residential" based on the "residential id". I tried making the filter in $args = array(); as

    'post_parent' => $parent_id

    and the $parent_id is something like this:

    global $parent_id;
    
    					if(isset($_GET['cat'])) { $url = $_GET['cat']; }
    					if($url="residential") { $parent_id = 145; }
    					if($url="commercial") { $parent_id = 30; }

    But it isn't working.

    I also hope the plugin author may respond. It would be nice to know how to do this.

  12. itissue
    Member
    Posted 9 months ago #

    Oh!!!! I got it! I didn't write my if statements correctly.

    global $parent_id;
    global $url;
    
    if(isset($_GET['cat'])) {
    	$url = $_GET['cat'];
    	if($url=="residential") { $parent_id = 30; }
    	elseif($url=="commercial") { $parent_id = 145; }
    	else $parent_id = "";
    }
    
    ........
    
    $args = array(
    						'post_type'					=> 'gallery',
    						'post_status'				=> 'publish',
    						'orderby'						=> 'post_date',
    						'posts_per_page'		=> -1,
    						'post_parent'	=> $parent_id
    					);
  13. bestwebsoft
    Member
    Plugin Author

    Posted 9 months ago #

    Hi itissue,

    Unfortunately this functionality is not provided.

    Sincerely,
    Support Team

  14. kchayka
    Member
    Posted 9 months ago #

    itissue, I would try to make it more dynamic so you don't have to hard-code names and IDs.

    The response from the plugin author is disappointing. How about adding it to the next release? Or at least say you'll consider doing that?

  15. itissue
    Member
    Posted 9 months ago #

    Thanks kchayka for being there so I'm not the only one on this thread. I couldn't figure out how to not hardcode the query string values without using SQL queries to get the table with the parent titles and ids to match with the children ones, which may also not be a good thing to do. Maybe that's better than hardcoding. I'll try working on this and then document it better so it might help someone in the future in case they are looking for the same functionality. I'll keep you posted.

    Thanks bestwebsoft for responding. Maybe you can work something out for the future? I do hope it may be in the future. Thanks for developing this plugin for us all to use. It's nice in that it's pretty simple and easy to set up.

  16. itissue
    Member
    Posted 9 months ago #

    Well I got the SQL statement to use:

    SELECT post_title, id
    FROM  wp_posts
    WHERE (
    post_parent =0
    AND  post_type =  "gallery"
    AND  post_status =  "publish"
    )

    Yay!! Getting there. (Where wp is is the prefix you use for your tables)

  17. itissue
    Member
    Posted 9 months ago #

    I've done it! Now everything is dynamic. I'll write an article on it after I'm done with the entire project and can show people. For now, here are some snippets. Suggestions for improvement are welcome.

    Note: This is all in gallery_template.php in your theme folder.

    Variables

    global $parent_id;
    global $cat_value;
    global $query_parent_id;
    global $query_parent_title;

    I made them global because they are used in and out of if and loops.

    $parent_id is what we're trying to obtain. $cat_value is the query string value. $query_parent_id is the parent id from the SQL query. $query_parent_title is the parent title from the SQL query.

    ---

    Here's the query I used:

    $parents = $wpdb->get_results("SELECT post_title, id FROM wp_posts WHERE (post_parent = 0 AND post_type = 'gallery' AND post_status = 'publish')");

    I want to get the post_title and id of the parent albums to use later.

    ---

    Here's where I'm getting the post_title and id from each array item. Then I'm comparing the parent_title with the query string title. I'm making the parent_title lowercase so they match since the query string is all lowercase but the album title is capitalized. There may need adjustments if say your album has more than one word and your query string uses dashes. Then you can use str_replace on the album title. Unless there's a better way.

    Then if the parent_title matches the query string value, then assign id to $parent_id.

    foreach($parents as $parent) {
    	$query_parent_id = $parent->id;
    	$query_parent_title = strtolower($parent->post_title);
    	if(isset($_GET['cat'])) {
    		$cat_value = $_GET['cat'];
    		// compare the queried parent_title with the query string value, then assign its id to $parent_id
    					if($query_parent_title==$cat_value) { $parent_id = $query_parent_id; }
    	}
    }

    ---

    Here's where I added the post_parent filter, and $parent_id finally comes into good use. It's saying find all gallery posts that are published and order them by post date, with no set posts per page, and have the same parent id as the one you found before through the query string and id matching.

    $args = array(
    	'post_type' => 'gallery',
    	'post_status' => 'publish',
    	'orderby' => 'post_date',
    	'posts_per_page' => -1,
    	'post_parent' => $parent_id
    );

    ---

    I forgot, you also need to have a page for the parent albums and link the albums to
    ?cat=album
    and where album is is the name of your album. This page you'll have to make yourself instead of with the auto-generated. I'm assuming there's a more automatic way to do this if you can write a program for it, but for now this is as far as I got.

    Feel free to share your ideas!

  18. itissue
    Member
    Posted 9 months ago #

    I found a way to make the page display the categories automatically instead of having to manually create the categories page content.

    Here's the gallery-template.php file with all the code needed to make albums and sub albums.

    http://pastebin.com/XvHrdyma

    You'll need to change
    $gallery_page = '/projects/';
    $category_page = '/projects-by-category/';
    $all_albums = 'All Projects »';
    $all_categories = 'Projects by Category »';

    $gallery_page is the page that you create to show the albums, using the gallery template.

    $category_page is the page that you create to show the categories or parent albums, using the gallery template as well.

    $all_albums is the text for the breadcrumb link for viewing all albums.
    $all_categories is the text for the breadcrumb link for viewing all parent albums.

Reply

You must log in to post.

About this Plugin

About this Topic