Search code examples
expressionengine

ExpressionEngine tag for knowing if you're on a entry page or not


How can you tell inside of a template if the page is being viewed as a single entry page or not?


Solution

  • You would use the {total_results} variable (link) inside of the {exp:channel:entries} loop that generates the entries that you are targeting. For instance, if you're displaying entries for a blog, your template code could look something like this:

    <ul class="entries">    
    {exp:channel:entries channel="blog"}
      {if "{total_results}"=="1"}
        <li class="single-entry">
          {title}
          {content}
        </li>
      {if:else}
        <li class="entry">
          <a href="#">{title}</a>
          <p>{excerpt}</p>
        </li>
      {/if}
      {if no_results}
        <li class="no-entries">No blog entries found.</li>
      {/if}
    {/exp:channel:entries}
    </ul>