Skip to content

Instantly share code, notes, and snippets.

@RyanRoberts
Created November 12, 2012 13:45
Show Gist options
  • Select an option

  • Save RyanRoberts/4059473 to your computer and use it in GitHub Desktop.

Select an option

Save RyanRoberts/4059473 to your computer and use it in GitHub Desktop.
If no results I don't want the .articles div or main h1. Without using {if no_results} to output content.
<div class="articles">
<h1>Recent Articles</h1>
{exp:channel:entries channel="articles"}
<article>
<h1>{title}</h1>
{body}
</article>
{/exp:channel:entries}
</div>
@Filipvds

Copy link
Copy Markdown
{exp:channel:entries channel="articles"}
   {if count == 1}<div class="articles"><h1>Recent Articles</h1>{/if}
    <article>
        <h1>{title}</h1>
        {body}
    </article>
    {if count == total_results}</div>{/if}
{/exp:channel:entries}

@cwcrawley

Copy link
Copy Markdown

You could probably do something like the following:

{exp:channel:entries channel="articles"}
{if count==1}

Recent Articles

{/if}

{title}

{body} {if count==absolute_count}

{/if}
{/exp:channel:entries}

@Filipvds

Copy link
Copy Markdown

@cwcrawley your example won't work with pagination (and when not on the first page).

{total_results} - Total results being displayed
{absolute_count} - The absolute “count” out of the current entries being displayed by the tag, including those entries on previous pages (if using pagination).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment