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.

Struggling With Relationships (the EE kind)

September 21, 2011 8:13pm

Subscribe [2]
  • #1 / Sep 21, 2011 8:13pm

    liquiduscreative

    13 posts

    Basically all I’m trying to do is relate news articles from a news channel to a specific company profile. I have a channel with several “Partner Company Profiles” which contain data about them. I also have a channel that contains just “Partner Company” news. All I want to do is pull in only the news articles related to that specific company. There’s probably a stupid obvious way to do this but I’m fairly new to EE.

    I’ve tried relationships and reverse relationships but it pulls in the wrong entries. I have a Relationship field in the News section and I’m relating that to the particular company. Seems logical enough to me but it’s not working! I’m sure there’s a smarter mind out there than mine that can give me clue! Thanks

    Here’s my code:

    {exp:channel:entries 
        channel="epic_global_partners" 
        disable="member_data|pagination" 
        sort="asc"
        limit="1"
    }        
    <div class="profile-heading"><h2>Featured Partner: <span>{title}</span></h2><p></div><!--end featured heading--><br />
        {embed="embeds/html_social_links"}<br />
    </div><!--end inner top--><br />
    <div class="page-expand"><br />
        <div id="profile-contents"><br />
            <div class="profile-data"><br />
                </p><h3>Company Data</h3>
    <p>                <ul><br />
                        <li>Industry: {categories} <span>{category_name}</span> {/categories}</li><br />
                        <li>Year Established: <span>{year_established}</span></li><br />
                    </ul><br />
                </p>
    
    <p>            </p><h3>Contact Information</h3>
    <p>                <ul><br />
                        <li>Phone: {epic_partner_phone}</li><br />
                        <li>Email: {epic_partner_email}</li><br />
                        <li>Website: {epic_partner_website}</li><br />
                    </ul><br />
                </p>
    
    <p>            </p><h3>Stock Performance</h3>
    <p>                <ul><br />
                        <li>Item: </li><br />
                        <li>Item: </li><br />
                        <li>Item: </li><br />
                    </ul><br />
    </div><!--end profile data--><br />
        <br />
    <div class="profile-logo">{epic_partner_logo_large}</div><!--end profile logo--><br />
    <div class="profile-hr"></div><br />
        <div class="profile-copy"><br />
            <div class="copy">    <br />
                {epic_partner_bio}<br />
    <div class="profile-hr"></div><br />
    </div><br />
    </div></p>
    
    <p><!--recent partners news--><br />
    <div class="profile-news-heading"></p><h2>{title} News</h2><p></div><!--end featured heading--></p>
    
    <p><br />
    {/exp:channel:entries}<br />
    {exp:channel:entries <br />
        channel="epic_partners_news"  <br />
        orderby="date"<br />
        limit="3"<br />
        paginate="bottom"<br />
        dynamic="no"<br />
    }</p>
    
    <p>{related_entries id="epic_partners_relationship"}</p>
    
    <p>    <div class="profile-copy"><br />
            <div class="copy"></p><h2><a href="http://{url_title_path=news_epic_partners/single}">{title}</a></h2>
    <p>    <div class="post-meta"><br />
            Posted on: {entry_date format='%m/%d'} in: {categories} <a href="http://{path=news_epic_partners}">{category_name}</a> {/categories}<br />
    </div><!--end post meta--><br />
    {exp:word_limit total="30"}<br />
        {page_body}<br />
    {/exp:word_limit}<br />
    <a href="http://{url_title_path=news_epic_partners/single}"><span class="readmore">read more…</span></a><br />
    <div class="profile-blog-hr"></div><br />
    </div><!end copy--><br />
    </div><!end profile copy--><br />
    {/related_entries}<br />
    {paginate}<br />
        <div class="paginate"><br />
            <span class="pagecount">Page {current_page} of {total_pages} pages</span> {pagination_links}<br />
    </div><!--end paginate--><br />
    {/paginate}<br />
    {/exp:channel:entries}<br />
    </div><!--end profile contents--><br />
    </div><!--end page expand-->

  • #2 / Sep 21, 2011 11:10pm

    Boyink!

    5011 posts

    Think about relationships as a “1-many” arrangement.  You have companies (1) and news (many). 

    With EE you want to put the relationship field on the side of the many (news). And for each news item you would choose a company (1). 

    Then to show, for each company, related news items you’d loop through the company channel and use the reverse_related_entries tag pair.

  • #3 / Sep 22, 2011 11:25am

    liquiduscreative

    13 posts

    Thank you sir, I finally figured it out. I had to remove all parameters from the channel loop to get it working. Thanks for your help!

    P.S. I enjoy your work, especially the adventure blog 😉  Cool stuff…take care.

    - Jay

  • #4 / Sep 22, 2011 6:45pm

    Boyink!

    5011 posts

    Good to hear!

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

ExpressionEngine News!

#eecms, #events, #releases