We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Relationship List with headers

Development and Programming

ThePigeonHold's avatar
ThePigeonHold
8 posts
12 years ago
ThePigeonHold's avatar ThePigeonHold

Hey Everyone,

I’m struggling a bit trying to create a list of entries with relationships.

My client is a home developer and they would like a list of their communities that are separated by the quadrant they exist in. For example:

North West Community Name Community Name

South Community Name

West Community Name

I’m not having any issues creating list. The problem I’m having is: when there isn’t a community related to a quadrant I don’t want the Quadrant title to show and I’m finding it difficult to find a solution.

Here is a sample of my code:

{exp:channel:entries channel="quadrants" site="home"}
  {if parents:no_results}
    <h2>{quadrant_title}</h2>
  {/if}
  {parents field="quadrant"}
    <a href="http://{path=communities/details/{parents:url_title}}">{parents:community_title}</a>

   {/parents}
{/exp:channel:entries}

Right now the conditional is showing all Quadrant titles that currently don’t have a community attached and I would like it to do the opposite.

I realize this is probably pretty simple but I’ve been banging my head against it for too long now. Any help would be greatly appreciated.

Thanks All!

       
Boyink!'s avatar
Boyink!
5,011 posts
12 years ago
Boyink!'s avatar Boyink!

So your relationship field is in the quadrants channel or the communities channel?

I think you want it in the communities channel, then quadrants as children, and code looking for children rather than parents.

       
ThePigeonHold's avatar
ThePigeonHold
8 posts
12 years ago
ThePigeonHold's avatar ThePigeonHold

Hi Mike,

Thanks for getting back to me and sorry for my not replying earlier.

Unfortunately, what I need has become a little more complicated. This is the new list structure required by the client:

North West:
-Community Name
--Development Name inside Community
--Development Name inside Community

-Community Name
--Development Name inside Community

East:
-Community Name
--Development Name inside Community
--Development Name inside Community

South:
-Community Name
--Development Name inside Community
--Development Name inside Community

-Community Name
--Development Name inside Community

So in addition to having Communities separated by the quadrant they exist in, I need to also display the developments that exist within each community.

So I have three channels of quadrants, communities, and developments. I have placed a relationship field in the communities channel that relates to quadrants and I have another relationship field in developments channel that relates to communities.

This is the code I currently have inside the template:

{exp:channel:entries channel="communities"}
  <h2>{quadrant:title}</h2>
  <ul>
    <li>
      <h3>{title}</h3>
      <ul>
        {parents field="development_assoc_community"}
          <li>{parents:title}</li>
        {/parents}
      </ul>
    </li>
  </ul>
{/exp:channel:entries}

Everything about this works except I get a doubling of each quadrant that has more than one community in it. Example:

North West:
-Community Name
--Development Name inside Community
--Development Name inside Community

North West:
-Community Name
--Development Name inside Community

East:
-Community Name
--Development Name inside Community
--Development Name inside Community

South:
-Community Name
--Development Name inside Community
--Development Name inside Community

South:
-Community Name
--Development Name inside Community

I feel like I’m sooo close on this but I can’t figure out how to get rid of that doubling. Any suggestions?

       
Boyink!'s avatar
Boyink!
5,011 posts
12 years ago
Boyink!'s avatar Boyink!

This all gets confusing in a hurry.

What seems to me is that you shouldn’t be using the parents tag.

If you think about this from the top down you should be stepping down a level,then stepping down a level again. The parents tag steps back up.

In other words I think you should be using nested child tags instead.

       
Visiluna's avatar
Visiluna
92 posts
12 years ago
Visiluna's avatar Visiluna

Seems to me that categories would be a more appropriate mechanism here than entry relationships.

You can set your tag to not show empty categories, and categories also already handles these parent/child structures.

Just a thought.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.