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.

Creating relationship between channel items

November 17, 2010 2:13am

Subscribe [3]
  • #1 / Nov 17, 2010 2:13am

    Heiko

    135 posts

    Hi there,

    a client of mine needs to setup a custom collection of quotes related to her work - movies.

    She wants an arbitrary selection of quotes to be randomly displayed on the homepage, but needs more specifically related quotes on the single_entry_template for each movie.

    Now, I have already setup the random display of arbitrary quotes on the homepage, which was a snap, but how can I further relate the movie-specific quotes to their respective movie template?

    I don’t know how to explain it better, but I need one publish form to enter quotes of the following two classes:

    arbitrary:  might be related to anything about her business, including movies
    specific: must be related to one movie only

    Can anybody help? Thanks!
    Heiko

  • #2 / Nov 18, 2010 5:27am

    e-man

    1816 posts

    Key word here is related. I think Playa is in order for this:
    http://pixelandtonic.com/playa
    Gives your client a drag and drop interface to relate quotes to an entry.

  • #3 / Nov 18, 2010 9:01am

    Heiko

    135 posts

    Well, thanks for your feedback, but I don’t think my client will pay for this feature or anything beyond. It was already hard enough to persuade her into buying EE. 😉

    Anyway, I can’t believe that there are no other options. I mean, how about assigning a tag to each quote and only show quotes, the tag of which matches the title of the channel entry currently displayed in the browser? Or maybe one can automatically create a category when publishing an entry and simply enter quotes to that category later on?

    I’m not a programmer, but this must be possible using PHP or RegEx. Despite my unbroken enthusiasm for EE it seems that a lot of advanced functionality is only available through paid addons. :-(

  • #4 / Nov 18, 2010 9:04am

    Boyink!

    5011 posts

    Well, thanks for your feedback, but I don’t think my client will pay for this feature or anything beyond.

    Guess it’s not important enough then?  Surely she’ll pay for it one way or another, either through an add-on or your time?

    Otherwise look at the native relationship field.  You’d add the field to the channel storing movie quotes, and relate them to the channel storing movies.

  • #5 / Nov 18, 2010 9:09am

    Heiko

    135 posts

    Yeah, you are definitely right about this, but I think at the end it’s really not important enough. 😉

    Thanks for the hint though, I will definitely check this out.

  • #6 / Nov 18, 2010 10:27am

    Heiko

    135 posts

    Hey there, Boyink!, thanks a lot! 😊

    It seems relationship fields were exactly what I was looking for. Great!

  • #7 / Nov 19, 2010 4:59am

    Heiko

    135 posts

    Alright, after some futile attempts of getting related_entries to work, I’ll surrender. Why doesn’t this work?

    {exp:channel:entries channel="main_channel"}
    <div class="article">
      <h1>{title}</h1>
      {body}
    </div>
    <div class="article">
      <h3>Quotes:</h3>
    <p>  {related_entries id="quote-related"}<br />
      </p><blockquote>
    <p>  {quote-body}<br />
      </p>
    </blockquote>
    <p>  {/related_entries}<br />
    </div> <br />
    {/exp:channel:entries}

    I setup the quote-related and quote-body fields in my quotes_channel and checked the fieldgroup assignment. Then I published an entry to the quotes_channel and selected the related entry from the main_channel using the drop-down menu on the publish form.

    Yet, no data from the quotes_channel is being pulled into the main_channel template.

    Anyone please! What’s wrong with my code?

    Thank you
    Heiko

  • #8 / Nov 19, 2010 8:11am

    Boyink!

    5011 posts

    I think you need to try the reverse_related_entries tag pair.

  • #9 / Nov 19, 2010 8:28am

    Heiko

    135 posts

    Man, you are the best! Thanks a lot, this worked flawlessly! 😊

  • #10 / Nov 19, 2010 8:32am

    Boyink!

    5011 posts

    Cool - glad it worked.

    The thing to remember is that when you are looping through the channel that “owns” the relationship field (quotes in this case) you use related_entries.  BUT - that tag pair is a bit mis-named because it’s plural, but will only ever return one result (in your case the Movie that the quote is related to).

    When you are looping through the channel that doesn’t own the relationship field, but is instead being pointed to by the relationship, that’s when reverse_related_entries comes into play (and is usually the far more handy and powerful tag).

  • #11 / Nov 19, 2010 8:42am

    Heiko

    135 posts

    Great to know about! And I’m glad that this was entirely possible without any addons. Thank you!

    I really need to delve a little deeper into EE’s possibilities.

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

ExpressionEngine News!

#eecms, #events, #releases