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.

Parent with two children

February 11, 2014 12:04pm

Subscribe [2]
  • #1 / Feb 11, 2014 12:04pm

    Finn

    40 posts

    Hi,

    I have a parent with two children, like this (or see the attachment).

              Product (parent)
                  /        \
                /            \
              /                \
      Artist (child)    Exhibition (child)

    The following code works. It gets me all Products that belong to a particular Exhibition.

    {exp:channel:entries channel="exhibition"} 
    
     {parents field="product_exhibition"}
        
         {parents:product_image:thumb}
        
         {parents:title}
    
     {/parents}
      
    {/exp:channel:entries}

    But I also want to get the Artist title for each Product, like this:

    {exp:channel:entries channel="exhibition"} 
    
     {parents field="product_exhibition"}
        
         {parents:product_image:thumb}
            
            PRODUCT_ARTIST:TITLE
        
         {parents:title}
    
     {/parents}
      
    {/exp:channel:entries}

    I’m not sure if EE allows for this - anybody have any ideas?

    Thanks for looking.

     

  • #2 / Feb 11, 2014 4:18pm

    Boyink!

    5011 posts

    Siblings?

  • #3 / Feb 11, 2014 5:06pm

    Finn

    40 posts

    Yes, thank you! (for some reason I’d thought siblings was same-channel only.)

    Here’s my new code:

    {exp:channel:entries channel="exhibition"} 
    
     {parents field="product_exhibition"}
        
         {parents:product_image:thumb}
            
             {siblings channel="artist" field="product_artist"}
                           
                           {siblings:title}
                    
                    {/siblings}
        
         {parents:title}
    
     {/parents}
      
    {/exp:channel:entries}

    It works great, except that for each entry it is outputting multiple artist names, rather than the single (correct) name for each entry… I’m hoping another one word answer can fix it!

     

  • #4 / Feb 11, 2014 5:17pm

    Boyink!

    5011 posts

    Sorry, my quota of one-word answers is filled for the day..😉

    Do those artists all share the same Parents (products)?

  • #5 / Feb 11, 2014 5:23pm

    Finn

    40 posts

    Thanks for offering more valuable words 😊

    Each product has a unique artist associated with it:

    Product 1 belongs to Artist 1
    Product 2 belongs to Artist 2
    Product 3 belongs to Artist 3

    So I should get:

    Product 1 image accompanied by Artist 1 name
    Product 2 image accompanied by Artist 2 name
    Product 3 image accompanied by Artist 3 name

    But in fact I get:

    Product 1 image accompanied by Artist 1 name, Artist 2 name, and Artist 3 name.
    Product 2 image accompanied by Artist 1 name, Artist 2 name, and Artist 3 name.
    Product 3 image accompanied by Artist 1 name, Artist 2 name, and Artist 3 name.

    If I had Artist 4, his name wouldn’t show up - only those Artists that are related to at least one image on the page show up.

    Hope that makes sense… and thanks!

  • #6 / Feb 13, 2014 6:03pm

    Finn

    40 posts

    Just to update this thread:

    This seems to work:

    {parents:product_artist}
                    
         {parents:product_artist:title}
                    
    {/parents:product_artist}

    And indeed, just this alone:

    {parents:product_artist:title}
  • #7 / Feb 15, 2014 12:34pm

    Finn

    40 posts

    Just realised that should you need to access grandchildren you can do:

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

ExpressionEngine News!

#eecms, #events, #releases