ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Pulling in specific gallery image into weblog entry.

August 10, 2007 9:02am

Subscribe [2]
  • #1 / Aug 10, 2007 9:02am

    Linda A

    666 posts

    I am trying to pull in images from a gallery with a weblog entry, and I am wondering if it is possible to do it so that only images where custom_field_one matches the title of the entry (alternatively, a segment) will be pulled in. Is there any way of doing that sort of selection within the gallery tag? Categories won’t work here because I’d need to make so many for this particular gallery.

  • #2 / Aug 10, 2007 9:07am

    stefanschuur

    21 posts

    I did this by using a paid module called Gallery Extended 2.0.2 from Solspace. You can find it here http://solspace.com/software/detail/gallery_extended/
    Any other solution is welcome though.

  • #3 / Aug 10, 2007 9:16am

    Linda A

    666 posts

    Ah, thanks. It looks quite nice and powerful, but I can’t quite justify going for a paid solution given the fairly limited use I’d put it to at this moment. 😊

    Edited to add: Looking at the documentation, it seems this can’t be used after the fact either, once the images are already uploaded. So it wouldn’t work for me anyhow.

  • #4 / Aug 10, 2007 3:17pm

    Ryan M.

    1511 posts

    Linda, I’m looking to do the exact same thing. I enabled custom field 1 so I could put a url title in there, and when that matches segment_1, show this particular image. If I figure out anything, I’ll let you know.

  • #5 / Aug 10, 2007 3:37pm

    Ryan M.

    1511 posts

    OK, I got this working for me, with a default image in case the query doesn’t return anything.

    {if segment_1 != ""}
    {exp:query sql="SELECT entry_id AS headerpic
    FROM exp_gallery_entries
    WHERE gallery_id = 3
    AND cat_id = 4
    AND custom_field_one = '{segment_1}'"}
    
            {if no_results}
                {exp:gallery:entries dynamic="off" gallery="header_images" entry_id="26"}
                    {image_url}
                {/exp:gallery:entries}
            {/if}
    
            {exp:gallery:entries dynamic="off" gallery="header_images" entry_id="{headerpic}"}
                {image_url}    
            {/exp:gallery:entries}
    
    {/exp:query}
        
            
    {/if}

    In English: if segment_1 is there, select from galleries (in the right category and gallery) where custom_field_one matches the segment, and return the ID of that pic. If there was no result, who the default header image. If there was a result, then by all means, show that pic!

    You may not need the outer if statement, and I’m sure your gallery and category numbers will be different. Hope that helps you out!

  • #6 / Aug 10, 2007 4:06pm

    Linda A

    666 posts

    That looks very promising. 😊 Do you think the same method could be used even if there are more than one gallery entry where the custom field matches? What I need to do is to randomly select 2 pictures out of several more where the custom field matches.

  • #7 / Aug 10, 2007 4:35pm

    Ryan M.

    1511 posts

    This is untested, but some quick googling on SQL + random results in something like this, maybe, sort of…

    {exp:query sql="SELECT entry_id AS headerpic
    FROM exp_gallery_entries
    WHERE gallery_id = 3
    AND cat_id = 4
    AND custom_field_one = '{segment_1}'
    ORDER BY RAND() LIMIT 2"}

    That just says “pick 2 random ones from the selection”.

  • #8 / Aug 10, 2007 5:02pm

    Linda A

    666 posts

    It works! Brilliant, thank you. 😊

  • #9 / Aug 10, 2007 5:16pm

    Ryan M.

    1511 posts

    No problem. For my next trick, I’d like to allow one image to be used multiple times, so you might fill out custom_field_1 with numerous entries separated by pipes:

    home|tour|about_us

    That might be a nice little addition (which you might need to enable PHP for…). This could almost be made into a plugin at that point. Hmm.

    We’ll see, it does what I need right now, so I need to move on to other things!

  • #10 / Aug 10, 2007 5:47pm

    Linda A

    666 posts

    Interesting. That’d be almost like adding tags to an image. Which no doubt would be a popular ability.

  • #11 / Aug 10, 2007 6:05pm

    Lisa Wess

    20502 posts

    You can tag entries with Tag 2 from solspace, which is currently in beta 😉

  • #12 / Aug 10, 2007 6:11pm

    Linda A

    666 posts

    Gallery entries as well?

  • #13 / Aug 10, 2007 6:13pm

    Lisa Wess

    20502 posts

    Yes. I don’t display the tags on my gallery, but you can see how I pull them out - weblog and gallery together - here.  It’s work-safe, just about my cats. =)

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases