Forum

Thread tagged as: Question, Blog, Gallery

Adding Gallery Album to Blog post

I was able to use the album list field type to select a gallery album on pages and then get that album to display on those pages, but I haven't been able to do the same for blog posts. This is what I have...

I added this to post.html:

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

And this to the single blog page:

<?php
    $album = perch_blog_custom(array('skip-template'=>true));
    if (is_array($album)) {
        // ['album'] is the ID of the field to get the slug from
        $albumSlug = $album[0]['album']['albumSlug'];
        perch_gallery_album($albumSlug);
    }
?>

Any ideas on where I've gone wrong?

Brad Hardinge

Brad Hardinge 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What result do you get?

I managed to get the gallery to output, but it's not getting the correct gallery - it just returns the first gallery every time no matter what is selected. I turned on debugging and I see this line in the SQL:

SELECT * FROM perch2_gallery_albums WHERE albumSlug= 'bali-food-safari'

That albumSlug is the same for all blogs even though different albums have been selected via the albumlist selector.

I assume this means this line is incorrect?

$albumSlug = $album[0]['album']['albumSlug'];

This is the array output...

Array ( [0] => Array ( [excerpt] => Array ( [raw] =>
Blog Excerpt

[processed] =>
Blog Excerpt

) [album] => Array ( [albumSlug] => bali-food-safari [_default] => bali-food-safari ) [postID] => 3 [postTitle] => Test Blog [postSlug] => 2014-03-30-test-blog [postDateTime] => 2014-03-30 15:41:00 [postDescRaw] =>
Blog Post

[postDescHTML] =>
Blog Post

[postDynamicFields] => {"excerpt":{"raw":"
Blog Excerpt<\/p>","processed":"

Blog Excerpt<\/p>"},"album":{"albumSlug":"bali-food-safari","_default":"bali-food-safari"}} [postTags] => [postStatus] => Published [authorID] => 1 [sectionID] => 1 [postCommentCount] => 0 [postImportID] => [postLegacyURL] => [postAllowComments] => 0 [postTemplate] => post.html [perch_excerpt] => Array ( [raw] =>

Blog Excerpt

[processed] =>
Blog Excerpt

) [perch_album] => Array ( [albumSlug] => bali-food-safari [_default] => bali-food-safari ) ) [1] => Array ( [excerpt] => Array ( [raw] => [processed] => ) [album] => Array ( [albumSlug] => test [_default] => test ) [postID] => 5 [postTitle] => Blog 2 [postSlug] => 2014-09-01-blog-2 [postDateTime] => 2014-09-01 19:04:00 [postDescRaw] =>
Blog 2

[postDescHTML] =>
Blog 2

[postDynamicFields] => {"excerpt":{"raw":"","processed":""},"album":{"albumSlug":"test","_default":"test"}} [postTags] => [postStatus] => Published [authorID] => 1 [sectionID] => 1 [postCommentCount] => 0 [postImportID] => [postLegacyURL] => [postAllowComments] => 1 [postTemplate] => post.html [perch_excerpt] => Array ( [raw] => [processed] => ) [perch_album] => Array ( [albumSlug] => test [_default] => test ) ) [2] => Array ( [excerpt] => Array ( [raw] => [processed] => ) [album] => Array ( [albumSlug] => test [_default] => test ) [postID] => 6 [postTitle] => Blog 3 [postSlug] => 2014-09-01-blog-3 [postDateTime] => 2014-09-01 19:12:00 [postDescRaw] =>
Blog 3

[postDescHTML] =>
Blog 3

[postDynamicFields] => {"excerpt":{"raw":"","processed":""},"album":{"albumSlug":"test","_default":"test"}} [postTags] => [postStatus] => Published [authorID] => 1 [sectionID] => 1 [postCommentCount] => 0 [postImportID] => [postLegacyURL] => [postAllowComments] => 1 [postTemplate] => post.html [perch_excerpt] => Array ( [raw] => [processed] => ) [perch_album] => Array ( [albumSlug] => test [_default] => test ) ) )
Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you trying to output one blog post or a list of them?

Just 1 blog post. This is the code on the single blog page...

<div class="content-main-inner">
    <?php perch_blog_post(perch_get('s')); ?>
    <?php
        $album = perch_blog_custom(array('skip-template'=>true));
        if (is_array($album)) {
            // ['album'] is the ID of the field to get the slug from
            $albumSlug = $album[0]['album']['albumSlug'];
            perch_gallery_album($albumSlug);
        }
    ?>
    <?php perch_blog_post_tags(perch_get('s'), 'post_tag_link.html'); ?>
</div>

Actually, I got it working using the following. Is there anything wrong with this method?

$blog_album = perch_blog_post_field(perch_get('s'), 'album', true);
perch_gallery_album($blog_album);
Drew McLellan

Drew McLellan 2638 points
Perch Support

That's fine. The problem with the original code was that your weren't filtering it to the post you wanted.