开发者

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开发者_JS百科 or not?


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>


You are better off checking for the presence of a segment to detect if you are on a single article view. There could be an instance where you only have one channel entry in your index view - eg if you are displaying news per month and its only 1st of the month.

By checking if segment_2 = url_title you'll also be able to keep pagination working correctly as /channel/p1 will work.

{if segment_2=="{url_title}"}  
    // show description
{if:else}
    // show summary
{/if}  


Following the insight from onlinepluz, consider it like

{if segment_2=="{url_title}"}  
        // show description
    {if:else}
        // show summary
    {/if}  

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜