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.

Entries within entries from a single channel template

August 04, 2014 4:44pm

Subscribe [2]
  • #1 / Aug 04, 2014 4:44pm

    KRInternetlaw

    1 posts

    Hello!
    Need some help and will try to explain as clearly as possible…

    I’m redesigning a law site.

    I have a template group called “attorneys” for each lawyer profile that has tabs holding various info. Right now, I have individual templates for each profile page that’s working fine, but I want to put all the same data into a channel to allow the client to make additions/changes etc.

    Moving the data into a channel, I’m using the index of the group which calls the new channel “attorneys” which holds all the data elements. Custom fields are used for each tabs’ content with {if} statements to show or hide based on if there’s content entered into the individual entries or not.

    Simple enough for a standard template/channel combo.

    Here’s where the tricky part comes in…

    The “attorneys” channel has a custom field called {blog_posts_tab}. It’s a yes/no radio selection so each entry can have the option to show or hide the “blog posts” tab and its content.

    The {blog_posts_tab} is supposed to display the entries written by that specific attorney that’s held in a separate channel “news_and_articles”.

    For example, if you’re viewing the ‘Karl’ attorney entry and click the ‘Blog Posts’ tab, it will display the title and date of the articles written by only Karl with links to those articles held in a separate channel.

    The problem I’m having now is that the “Blog Posts” tab is empty and not pulling any data, only the title and entry of the entry you’re viewing.

    I’ve tried using:

    {exp:channel:entries channel="attorneys|news_and_articles"}

    combined with

    {if blog_posts_tab == 'Yes' || channel_short_name == "news_and_articles"}

    Here’s the partial template code:

    {exp:channel:entries channel="attorneys|news_and_articles"}
        <!-- ========== BIO DETAIL ========== -->
        <div data-equalizer class="row">
            <div data-equalizer-watch class="large-6 columns medium-6 large-push-6 end">
                {attorney_portrait}
            </div>
            <div data-equalizer-watch class="large-5 columns medium-6 large-offset-1 large-pull-6">
                <div class="vertical-align">
                    {body}
                    <h5><a href="http://tel:" class="normal">{attorney_phone_number}</a>
                      {if attorney_phone_extension != ""}, {attorney_phone_extension}{/if}</h5>
    <p>                </p><h5><a href="mailto:{attorney_email}" class="normal">{attorney_email}</a>
                    </h5>
    <p>                {if v-card != ""}<a href="http://{v-card}" class="button">V-card</a>{/if} </p>
    
    <p>                {if attorney_linkedin_profile != ""}<br />
                    </p><h5>
                        <a href="http://{attorney_linkedin_profile}" class="normal" target="_blank" rel="noopener">_                        /img/global/icon-social-square-blue-linkedin.svgLinkedIn Profile</a>
                    </h5><p>{/if}<br />
                </div><br />
            </div><br />
        </div><br />
        </p>
    
    <p>            <!-- ==========   TABS CONTENT   ========== --><br />
                <div class="tabs-content"><br />
                    <div id="tab-1" class="content active"><br />
                        <div class="large-12 medium-11 columns medium-centered"><br />
                            {tab-1-content}<br />
                        </div><br />
                    </div></p>
    
    <p>                {if tab-2-content != ""}<br />
                    <div id="tab-2" class="content"><br />
                        <div class="large-12 medium-11 columns medium-centered"><br />
                            {tab-2-content}<br />
                        </div><br />
                    </div>{/if} </p>
    
    <p>                {if tab-3-content != ""}<br />
                    <div id="tab-3" class="content"><br />
                        <div class="large-12 medium-11 columns medium-centered"><br />
                            {tab-3-content}<br />
                        </div><br />
                    </div>{/if} </p>
    
    <p>                {if tab-4-content != ""}<br />
                    <div id="tab-4" class="content"><br />
                        <div class="large-12 medium-11 columns medium-centered"><br />
                            {tab-4-content}<br />
                        </div><br />
                    </div>{/if} </p>
    
    <p>                {if blog_posts_tab == 'Yes' || channel_short_name == "news_and_articles"}<br />
                    <div id="tab-5" class="content"><br />
                        <div class="large-12 medium-11 columns medium-centered"><br />
                            <ul class="no-bullet"><br />
                                <li><br />
                                    </p><h6><a href="http://{title_permalink}">{title}_                                    <div class="text-serif">_                                      <small>{entry_date format="%l, %F %d, %Y"}</small>_                                    </div></a>
                                    </h6>
    <p>                                <hr><br />
                                </li><br />
                            </ul><br />
                        </div><br />
                    </div><br />
                    {/if}<br />
        {/exp:channel:entries}

    Is something like this possible??? Do I need an extra plug-in like Stash?

    Here’s the template that’s working:
    http://www.krinternetlaw.com/attorneys/karl-kronenberger-profile

    And entry that’s not working:
    http://www.krinternetlaw.com/attorneys/karl-kronenberger

    Thanks so much!!!
    Danny

  • #2 / Aug 05, 2014 5:43am

    Rob Allen

    3114 posts

    The easy solution is to use the Author data to control the profile and blog entries.

    So assuming the “author” of the profile entry is Karl Kronenberger (set under the Options tab on publish/edit page) then you have a number of variables to play with including username and author_id.

    Here’s one approach using an embed template to pull in blog posts for an attorney.

    {exp:channel:entries channel="attorneys"}
    
    Profile stuff…
    
      <h2>Blog posts by {title}</h2>
    <p>  {embed="attorneys/_blog-posts" the_author="{author_id}"}</p>
    
    <p>{/exp:channel:entries}

    Then your embed template code:

    {exp:channel:entries channel="news_and_articles" author_id="{embed:the_author}"}
      {title}
    {/exp:channel:entries}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases