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

How to test for last entry with a parent relationship?

How Do I?

Gusto's avatar
Gusto
31 posts
about 8 years ago
Gusto's avatar Gusto

I’m trying to output a list of parent relationships and fire a closing </div> tag. The problem is I’m getting the </div> tag after the 1st entry, not the final entry. If I place an integer into the count statement that equals the total entries, it works. But, of course, I need a dynamic solution that recognizes the final entry.

This is what I’m trying to do:

{parents field="movie_links_relate" status="not closed"}
   {if parents:count == "1"}
    <div id="related_posts" class="theme_article">
     <div class="subtitle_area">
      <h3 class="post_related_title theme_subtitle">Related news about <em>{title}</em>
      </h3>
     </div>
   {/if}
     <div class="related_posts_item related_post_item_{parents:count} post_thumb down-1">
      <a href="http://{parents:title_permalink=">_      </a>         
      <div class="post_content_wrapper theme_puzzles" data-puzzlecolor="{exp:randomizer:set_three}">
       <h3 class="post_subtitle"><a href="http://{parents:title_permalink=">{parents:title}</a>
       </h3>
       <div class="reviews_summary blog_reviews theme_puzzles">
        <div class="criteria_summary criteria_row">
        </div>
       </div>
        <div class="post_descr">{parents:pull_quote}
        </div>
        <div class="post_content_padding theme_puzzles">
        </div>
      </div>
     </div>
   {if parents:count == total_results}
    </div>
   {/if}
{/parents}

I’m running EE 3.5.7

Thank you!

       
James Mathias's avatar
James Mathias
225 posts
about 8 years ago
James Mathias's avatar James Mathias

Hi,

total_results needs to be prefixed just like count does. So {if parents:count == parents:total_results} should get you the result you want.

       
Gusto's avatar
Gusto
31 posts
about 8 years ago
Gusto's avatar Gusto

Thanks again James. That’s two in a row… I appreciate your help!

       
James Mathias's avatar
James Mathias
225 posts
about 8 years ago
James Mathias's avatar James Mathias

No worries at all!

       

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.