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.

Break out of Weblog Entries tag If...

December 21, 2010 11:24am

Subscribe [4]
  • #1 / Dec 21, 2010 11:24am

    Jacob Graf

    163 posts

    I want to run a piece of code only if there is more than one entry returned. What’s happening though is that the code is run multiple times because there is more than one entry returned. Is there a way to check the conditional and then jump out of the Weblog Entries loop? Or is there a way to set a dynamic variable based on the same Weblog Entries loop higher up on the page and then check that later in the page instead of re-running the loop? Any other ideas? It’s probably something simple, but I am over-thinking it!

    {exp:weblog:entries weblog="scroller"} 
        {if total_results > 1}
            <a href="#id=prev_scroller"><< Previous</a>
            <a href="#id=next_scroller">Next >></a>
        {/if}
    {/exp:weblog:entries}
  • #2 / Dec 22, 2010 4:02am

    John Henry Donovan

    12339 posts

    Hi Jacob,

    Add the {paginate} variable pair around your next and previous and that will pull them out for you

    {exp:weblog:entries weblog="scroller"} 
        {paginate}
          {if "{total_pages}" != 1}
            <a href="#id=prev_scroller"><< Previous</a>
            <a href="#id=next_scroller">Next >></a>
           {/if}
        {/paginate}
    {/exp:weblog:entries}

    Does that help?

  • #3 / Dec 27, 2010 12:13am

    Jacob Graf

    163 posts

    John,

    I am not trying to do anything with the pagination feature of EE, I just want to run a block of code ONLY if there is more than one result from the weblog entries tag. What’s happening though is that if there is indeed more than one result, the code I want to run gets run multiple times based on how many results are returned. I only want the code to run once. Thanks for your help!

  • #4 / Dec 27, 2010 4:19pm

    Ingmar

    29245 posts

    Try to add something like

    {if count == "1"} ... {/if}

    Even if it’s evaluated multiple times it will only match once.

  • #5 / Dec 28, 2010 12:13am

    Jacob Graf

    163 posts

    Perfect! Works like a champ Ingmar! Thanks!

    I am wondering if there are any more use cases for having a tag pair in which anything inside that tag pair will only be run once inside an entries/comments tag?

  • #6 / Dec 28, 2010 10:14am

    Sue Crocker

    26054 posts

    Using count and restricting it to one is the best way of doing things. Glad Ingmar was able to help. Don’t hesitate to post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases