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.

Loop problem

March 11, 2011 2:41pm

Subscribe [4]
  • #1 / Mar 11, 2011 2:41pm

    marianway

    24 posts

    I realise this is going to be something simple I am doing wrong… 

    I have a weblog with 5 trainers in it, and another with testimonials - 2 each - which is linked.

    I am trying to output a list of all ten testimonials, under a heading, “What participants say”.

    All is working ok, except I am getting the heading up 5 times - once for each trainer.

    I will be really grateful if anyone can help.

    Here’s the code:


    {exp:weblog:entries weblog="trainers" orderby="date" sort="asc" disable="categories|pagination|trackbacks"}
    {reverse_related_entries weblog="testimonials" limit="10" }
    {if count == 1}

    <div class=“section” id=“testimonials”>

    What participants say

    <ul>
    {/if}

    <li>

    {g_body}

    </li> 
          {if count == total_results}

          </ul>
          </div><!—/#testimonials—>
          {/if}
    {/reverse_related_entries}
    {/exp:weblog:entries}

  • #2 / Mar 11, 2011 3:44pm

    Kevin Cupp

    791 posts

    I’d guess {count} is getting reset with each new instance of {reverse_related_entries}, so you’re actually getting the current {count} of the related entry you’re displaying instead of the overall items in “trainers.” You could probably move the {if count == ...} statements outside of the {reverse_related_entries} tag pair and have it work the way you want.

  • #3 / Mar 11, 2011 5:34pm

    Sue Crocker

    26054 posts

    Thanks for the assist, Kevin.

    marianway - does the advice from Kevin help?

  • #4 / Mar 11, 2011 7:38pm

    marianway

    24 posts

    Hi Kevin & Sue

    Thanks for the advice, unfortunately it doesn’t work… now I only have the 2 testimonials from the first trainer showing up, and each has its own heading…

    I would be grateful for any more ideas!

    Marian

  • #5 / Mar 12, 2011 8:30am

    marianway

    24 posts

    Hello again,

    I have now solved this problem.

    I had to take these two lines:

    <div class=“section” id=“testimonials”>
    What participants say

    and put them outside the weblog entries tag.

    This messed up the look of it, but have sorted that out now.

    Thanks for your help!

    Marian

  • #6 / Mar 13, 2011 7:54pm

    John Henry Donovan

    12339 posts

    Marian, glad you found a solution. Feel free to start a new thread if you have any more questions

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

ExpressionEngine News!

#eecms, #events, #releases