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.

Reverse_Related_Entries Conditional Question

March 26, 2008 11:39pm

Subscribe [2]
  • #16 / Mar 27, 2008 9:31pm

    Joey Trimmer

    128 posts

    Ahh…also, the url_title will only work if we are on a “portfolio” detail page link

    But to display the projects I’ve used a “project” detail page. So maybe if i can figure out how to display both weblogs using the same template?

    p.s. sorry the naming conventions are sort of confusing. “Our_Work” weblog entries display on portfolio template and the subnav “Project” weblog entries display on the project template.

  • #17 / Mar 27, 2008 9:55pm

    Robin Sowell

    13255 posts

    See- this is where I get fuzzy w/what you’re going for.  IF you want that right nav to be the same on the project page and the portfolio page?  Then this will work.  Getting the url_title is the only tricky bit- but we can get it.  But- I’m assuming that when you’re on a project page?  That right nav should look basically the same as if you were on the Portfolio page for whatever portfolio that project is in.

  • #18 / Mar 27, 2008 9:57pm

    Robin Sowell

    13255 posts

    To expand- hard code the embed variable a la:

    {embed="sidebars/nav_project" parent_url="parent_project_muscular_dystrophy1"}

    If we have our conditionals right?  Then when you’re on any project page, that right nav should be identical to the right nav here.

  • #19 / Mar 27, 2008 9:57pm

    Joey Trimmer

    128 posts

    No, you’re exactly right. The right nav should look like it does on the Portfolio page.

  • #20 / Mar 27, 2008 10:06pm

    Joey Trimmer

    128 posts

    To expand- hard code the embed variable a la:

    {embed="sidebars/nav_project" parent_url="parent_project_muscular_dystrophy1"}

    If we have our conditionals right?  Then when you’re on any project page, that right nav should be identical to the right nav here.

    ohhh neat, didn’t know you could do that. Should my embedded variable on nav_project still look like this?

    {if embed:related == url_title}
    content
    {/if}

    This isn’t working if so.

  • #21 / Mar 27, 2008 10:30pm

    Robin Sowell

    13255 posts

    Hm- should work.  I don’t have great test data- but this worked:
    My embed:

    {embed="site/test" related="saef_calendar"}

    The embedded page- site/test:

    <!--begin #right_sidebar-->
      <div id="right_sidebar">
        {exp:weblog:entries weblog="downloads" dynamic="off"}
        <ul>
          <li><h3><a href="http://{url_title_path=how/portfolio}class=on">{title}</a></h3>
    <p>          <ul><br />
    {if embed:related == url_title} <br />
                {reverse_related_entries sort="asc"}<br />
                <li><a href="http://{url_title_path=how/project}class=on">- {title}</a></li><br />
                {/reverse_related_entries}<br />
    {/if}<br />
              </ul><br />
          </li><br />
        </ul><br />
        {/exp:weblog:entries}<br />
      </div><!--/end #right_sidebar-->

    I end up with only the children of the saef_calendar showing.  And related entries of other entries in ‘downloads’ don’t.  Even the class=on bit seems to be working, though it wasn’t my focus. 

    Spot anywhere we differ?

  • #22 / Mar 27, 2008 10:32pm

    Robin Sowell

    13255 posts

    Aha- just spotted it.  Your embed is:

    {embed="sidebars/nav_project" parent_url="parent_project_muscular_dystrophy1"}

    NOTE- you named the variable parent_url.  But- in the embedded template, you’re calling it ‘related’:

    {if embed:related == url_title}
    content
    {/if}

    Need to match- then it should work.

  • #23 / Mar 27, 2008 11:04pm

    Joey Trimmer

    128 posts

    Oh good catch!

    Woohoo, we’re one step closer! It displays correctly with our hardcoded embedded variable!

    what a dumb error on my part too, phew. Now to figure the php part out.

  • #24 / Mar 27, 2008 11:11pm

    Robin Sowell

    13255 posts

    Whee!  OK- I’m starting to fade, but let’s see if we can kill it off by getting it dynamic.  PHP parsing turned on, parsed on output.

    Before the weblog tag that shows your content, put

    <?php $url=''; ?>

    Wherever.  We just want to be sure the variable is defined, even if the weblog tag ends up pulling back nada.  Inside the tag, use the related entries tag to get the url_title of the parent.  Or the child.  Whatever- I still get confused on that one.

    {exp:weblog:entries stuff…}
    More stuff
    
    {related_entries id="field_name"}
    <?php $url='{url_title}'; ?>
    {/related_entries}
    {/exp:weblog:entries}

    Basically- just add in the related_entries tag- define the php variable inside there.  Be sure the id is correct- unlike the reverse related, that’s required for this variable pair.

    Then- just echo it out as your embed variable value:

    {embed="sidebars/nav_project" related="<?php echo $url; ?>"}

    Er- be sure the embed variable name is still correct.  But anyhoo- that’s how we’re shooting for making it dynamic.  Untested- but I think it should work.

  • #25 / Mar 27, 2008 11:22pm

    Joey Trimmer

    128 posts

    Robin you’ve been amazing, I’m absolutely glad we made it this far and couldn’t have done it without you.

    This doesn’t seem to work just yet but I’ll keep hammering at it.

    I cleared the url_title at the very top

    <?php $url=''; ?>

    then within my weblog tag

    {related_entries id="which_client"}
    <?php $url='{url_title}'; ?>
    {/related_entries}

    and finally in my embed

    {embed="sidebars/nav_project" parent_url="<?php echo $url; ?>"}
  • #26 / Mar 27, 2008 11:25pm

    Joey Trimmer

    128 posts

    WAAAAIT! sorry sorry sorry. it works PERFECTLY! you’re amazing Robin. 😊 😊

    I had reset the parsing and just double checked to make sure it was on output and ta-da!

  • #27 / Mar 27, 2008 11:28pm

    Robin Sowell

    13255 posts

    Wheeee!  OK- I’m for bed.  Will drop in tomorrow to see where you’re at on next/prev.  Which I fear will be tricky.

  • #28 / Mar 27, 2008 11:29pm

    Joey Trimmer

    128 posts

    Again, thank you so much for sticking it out with me throughout the day. Phew! 😊

  • #29 / Mar 28, 2008 2:02pm

    Joey Trimmer

    128 posts

    Morning!

    It seems there’s really only one last issue with the reverse_related_entries that I’ve yet to solve. I need to figure out a solution to only show next/prev links if it’s within the related entry. However, default next/prev code cycles through all entries in order by date. The date ordering is fine but I need to refine it so that it doesn’t cycle through all entries. Again, just within the related entry.

    I wonder if using a conditional to limit pagination would work over using the next/prev tags?

    Or alternately, if there was a way to grab all the entry_id’s from weblog “Project” that are related in the main template I could embed that in a new template and plug it into the next/prev entry_ field. I don’t know how to send multiple variables like that (let alone separated by a | ).

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

ExpressionEngine News!

#eecms, #events, #releases