x
 
Create New Page
 View Previous Changes    ( Last updated by tbritton )

Gallery Relationships

Using Gallery Relationships (a special case of relationships in EE) allows you access to the best of two worlds: Image browsing, organization, batch upload, and the ability to select a single image from a drop-down menu in a weblog entry.

I have succeeded in getting relationships to work in placing photos in my weblog entries, but it took a bit of trial and error, as the documentation for both relationships and the gallery are lacking in this “combined use” of their features.

Here’s how it is done, or at least how I accomplished it. Many variations are possible.

First, I added a custom field to my publish pages of the kind, “relationship”. cf_gallery_relationship is what I called the custom field. Also, named it Gallery Relationship for the heading appearing on the publish/edit page.

This was not a regular weblog kind of relationship, but specifically a gallery relationship. You have to select the lower radio button, and then assign the specific gallery to this that this relationship will relate to when using this relationship field. I related it to a gallery that I had already uploaded some test images to.

When publishing or editing a post in that particular weblog now containing this new custom field, a drop-down list of the image names in that gallery now existed, and I selected one of the images from that list after giving my post a title and some body text.

(Note 1: When entering the title, the headings for each photo as entered in the gallery appear for you to select among as a drop-down list, letting you title the entry the same as the heading for the photo in the gallery. A nice convenience!)

(Note 2: This relationship field drop-down list apparently provides an image number, perhaps, or some other unique number generated by EE as a related_entries id number for the custom field entry when it is later being used as a variable in your template.)

(Note 3: Now that this is working, I am definitely creating a gallery just for images that I can insert into posts for graphical sweetening, so that my site has more images being used on it! (It is totally image-less currently.) I can see lots of uses for this trick, especially as it makes it so easy to change an image for a particular post or article, selecting from a drop down list of existing pics. Next trick - multiple pictures for one article by creating multiple gallery-relationship fields!)

_________________________________________________________________________________

The article template then needed the gallery image relationship to be put into it for display. After the exp:weblog:entries opening tag, and after the title and body and extended text variable tags, I put in the following code:

{related_entries id="cf_gallery_relationship"} {!-- notice, quotes only, no curly braces on fieldname! --}
{
!-- another way of putting this would be to say
{related_entries id
="short_name_of_gallery_relationship_custom_field"}
--}

<div>
<
img src="{image_url}" width="{width}" height="{height}" border="0" alt="{title}" title="{title}" />
</
div>

<
h3>{title}</h3>

{caption}

{if allow_comments}
<a href="{id_path=gallery/comments}">{if comment_total == 0}No comments have been submitted yet{/if}{if comment_total == 1}1 person has commented{/if}{if comment_total > 1}{comment_total} people have commented{/if}</a>
{/if}

<p>This image has been viewed {views} {if views == 1}time{/if}{if views != 1}times{/if}</p>

{/related_entries}

No exp:gallery:entries tag, just what you see above! The docs aren’t clear on this, so I naturally assumed you needed an exp:gallery:entries tag, but that clearly didn’t work!

It is simpler than that, only necessitating the related_entries opening and closing tags! (And, of course, the /exp:weblog:entries closing tag after all of this!) The related_entries id apparently “explains it all” for us that this is a gallery relationship!

I hope that helps you out. This is my first attempt to be helpful in the wiki! But I just figured this out tonight, so thought I’d follow up with an entry. Original post entry in forums
Terry

Categories:

Category:EE Coding
Category:Image Gallery
Category:Relationships
Category:Tutorials