Forum

Thread tagged as: Question, Blog, Gallery

Using a Gallery Album in a Blog post type

I have a standard blog post type called 'Default' and I'm now building another one called 'Photo Essay', which will be images only. What is the best way to pull in a gallery album for that Post Type only?

Can I use a slug from index.php (depending on what post was chosen) to select a particular post type?

This thread specifies close to what I'd like to do, the difference being, I need a way for post.php to know which post type is displaying. https://forum.grabaperch.com/forum/09-01-2014-adding-gallery-album-to-blog-post?page=1

Mat Ranson

Mat Ranson 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you using the albumlist field type?

I am, yes. Currently photoessay.html (a new blog post type file) contains

<perch:blog id="album" type="albumlist" label="Blog Gallery" suppress="true" order="2" />

Which is fine. The issue is how (blog) post.php deals with this because unless this is still in place:

perch_blog_post(perch_get('s'));

...all my standard blog posts won't display when selected.

As the other thread says, using this code works just fine to pull the gallery in:

$gallery_album = perch_blog_post_field(perch_get('s'), 'album', true);
perch_gallery_album($gallery_album);

So my challenge is how post.php knows what type of blog post type it should be showing (standard / with a gallery album / etc.). I understand what needs to change, where, just not...how! Thanks.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What does this output?

perch_blog_post_field(perch_get('s'), 'postTemplate');

It just outputs "post.html" in text on the page.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, great.

switch(perch_blog_post_field(perch_get('s'), 'postTemplate', true)) {

    case 'post.html':
        perch_blog_post(perch_get('s'));
        break;

    case 'photoessay.html':
        perch_blog_post(perch_get('s'));
        $gallery_album = perch_blog_post_field(perch_get('s'), 'album', true);
        perch_gallery_album($gallery_album);
        break;

}

Hmm, so now I change the post type in the CMS, I select a gallery, save, no problem. The entire process is fine except it outputs a blank page for photoessay.html. However, post.html displays fine.

My bad. I hadn't altered the path to the alternative post types. So this is the working code:

switch(perch_blog_post_field(perch_get('s'), 'postTemplate', true)) {

    case 'post.html':
        perch_blog_post(perch_get('s'));
        break;                      

    case 'posts/photoessay.html':
        $blog_album = perch_blog_post_field(perch_get('s'), 'album', true);
        perch_gallery_album($blog_album);
        perch_blog_post(perch_get('s'));
        break;
}

Thanks so much Drew!