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.

Single entry page - if first/last entry conditional

September 21, 2012 12:02pm

Subscribe [1]
  • #1 / Sep 21, 2012 12:02pm

    soundseller

    52 posts

    Hello,
    how can I find out if there is a next or previous entry available when I’m on a single entry page?
    Basically I want to know whether I am looking at the last or first entry of the channel.

    {exp:channel:entries channel="{segment_2}" require_entry="yes" limit="1" disable="categories|category_fields|member_data|trackbacks"}
    
    e.g.
    {if last_entry} do this{/if}
    {if first_entry} do that {/if}
    
    {/exp:channel:entries}

    Thanks!

  • #2 / Sep 24, 2012 3:35am

    Kevin Smith

    4784 posts

    Hi soundseller,

    Sounds like you could achieve what you’re looking for with the next/previous pagination method, outlined here. Does that help?

  • #3 / Sep 25, 2012 3:28am

    soundseller

    52 posts

    Thanks for helping,
    unfortunately it doesn’t seem to work for me.
    When I try:

    {exp:channel:entries channel="{segment_2}" paginate="top" require_entry="yes" limit="1" disable="categories|category_fields|member_data|trackbacks"}
    
    {paginate}
            {if previous_page}
               do this
            {/if}
            {if next_page}
                do that
            {/if}
        {/paginate}
    ...


    Nothing is displaying at all.
    I have to mention again, that this is intended to be used on a single entry page.

    What I am trying to achieve is to find out, if it is the first page and apply a different ce_cache tag, so I don’t have to remove all cached entries, when publishing a new post.

    The first entry will obviously have no cached “next link”, so every time I publish a new entry I have to delete all cached “prevnext_network” items.

    But I would like to be able to delete only the first entry(the only one that has actually changed).
    I hope this makes sense.

    {if first_page}
    {exp:ce_cache:it tags="first_page_prevnext_network" seconds="{cache_time}"}
    {/if}
    {if not_first_page}
    {exp:ce_cache:it tags="not_first_page_prevnext_network" seconds="{cache_time}"}
    {/if}
          <!--Pagination-->
          <div class="pagination clearfix">
           {exp:channel:prev_entry channel="{segment_2}"}
            <div id="prev_entry">
               <a href="/blog/{segment_2}/{url_title}class=prev_link">{exp:eehive_hacksaw chars="25" append = "..."}{title}{/exp:eehive_hacksaw}</a>
            </div>
           {/exp:channel:prev_entry}
    
           {exp:channel:next_entry channel="{segment_2}"}
            <div id="next_entry">
             <a href="/blog/{segment_2}/{url_title}class=next_link">{exp:eehive_hacksaw chars="25" append = "..."}{title}{/exp:eehive_hacksaw}</a>
            </div>
           {/exp:channel:next_entry}
          </div>
    
         {/exp:ce_cache:it}

    Thanks

  • #4 / Sep 26, 2012 12:52pm

    Kevin Smith

    4784 posts

    Ah, I see. Yeah, that’s different than I was originally thinking. You’re right in going with the exp:channel:prev_entry and exp:channel:next_entry tags.

    In that line of thinking, it seems like this part of the Next/Previous Entry Linking user guide article might be helpful:

    If you are viewing the most recent entry in your channel, then the “next_entry” tag’s contents will not be shown (since there is no “next entry”). Likewise, when you are viewing the oldest/first entry in the channel the “previous_entry” content will not be shown.

    Does it work if you stick the relevant CE Cache tags within the exp:channel:prev_entry and exp:channel:next_entry tags?

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

ExpressionEngine News!

#eecms, #events, #releases