• Resolved itissue

    (@itissue)


    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/

Viewing 2 replies - 16 through 17 (of 17 total)
  • Thread Starter itissue

    (@itissue)

    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!

    Thread Starter itissue

    (@itissue)

    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.

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘Albums and Sub Albums’ is closed to new replies.