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.

How to fake pagination count on single-entry pages?

March 26, 2011 2:38pm

Subscribe [3]
  • #1 / Mar 26, 2011 2:38pm

    rmedek

    131 posts

    I’m building a photo gallery where the index page is an archive of all entries, shown as thumbnails. Clicking on a thumbnail takes you to a single-entry page which shows the photo.

    Say there are 10 photos total, and you click on the third one—I would like the single-entry page to display “3 of 10,” with links to the next and previous entries.

    Next/previous pages are no problem, the total entry count I figure I can do with a query call or a separate exp:channel call, but the entry’s order I can’t figure out. The closest thing I can think of would be to loop through each entry, add to a counter, stop when I match the entry ID, display the counter. But it seems like a lot of overhead.

    Any ideas?

  • #2 / Mar 26, 2011 3:16pm

    John St-Amand

    865 posts

    You could certainly do it with a custom query, which is not my area of expertise, but there is an add-on that would certainly shortcut that for you.  Have a look at Entries Number on devot-ee.com.

  • #3 / Mar 26, 2011 3:50pm

    rmedek

    131 posts

    Thanks John. I’m holding out for an in-the-box solution, though, plus this plugin looks like it’d have more overhead than a loop through the channel.

  • #4 / Mar 26, 2011 4:05pm

    John St-Amand

    865 posts

    Query is probably slightly lower overhead, but a loop through the channel ought to work. The other thing you could do is simply post the entry’s count I to the URL and the use that segment in the single entry view as your individual count number.  But a loop through the entries is probably cleaner. If you have most other parameters that you’re not using disabled, it should stay pretty efficient. Good luck.

  • #5 / Apr 15, 2011 12:53pm

    James Smith

    259 posts

    rmedek did you come up with a solution for this one? I have the same need…

  • #6 / Apr 15, 2011 2:43pm

    rmedek

    131 posts

    Well, it’s not the most elegant solution, but it’s getting the job done for the moment. In my single-entry page, inside the channel:entries tag, I have this code:

    
        <span class="page-count">{embed="includes/pagination" this_channel="{this_channel}" entry_id="{entry_id}"}</span>
        {exp:channel:next_entry channel="{this_channel}"}<a href="http://{id_path=gallery/comments}class=prev">« newer</a>{/exp:channel:next_entry}
        {exp:channel:prev_entry channel="{this_channel}"}<a href="http://{id_path=gallery/comments}class=next">older »</a>{/exp:channel:prev_entry}
    

    Then, in the includes/pagination template, I have:

    <?php $count = 1; ?>
    
    {exp:channel:entries channel="{embed:this_channel}" disable="categories|member_data|trackbacks|pagination" limit="1000" orderby="date" sort="desc" dynamic="no"}
        {if {entry_id} == embed:entry_id}
            <?php echo $count; ?> of {total_results}
        {if:else}
            <?php $count++; ?>
        {/if}
    {/exp:channel:entries}

    …PHP is enabled in includes/pagination. Basically it puts the pagination loop in an include; the loop orders all of the entries by date and starts counting. When it hits {embed:entry_id} (the current entry), it stops and shows the count. Hope that helps…

  • #7 / Apr 15, 2011 3:06pm

    James Smith

    259 posts

    Thanks rmedek. I’ve actually just worked around it myself using the excellent String plugin to set some variables and then recall them inside the main loop. It still requires two channel:entries loops, but only one template, no embeds or template php. (http://www.emarketsouth.com/add-ons/string-plugin/). You could also do this with LG Replace, or MX Jumper.

    {exp:string:set name="subNav"}
        {exp:weblog:prev_entry weblog="the_weblog"}<li id="nav-prev"><a href="http://{path=capabilities}">{title}</a></li>{/exp:weblog:prev_entry}
        {exp:weblog:next_entry weblog="the_weblog"}<li id="nav-next"><a href="http://{path=capabilities}">{title}</a></li>{/exp:weblog:next_entry}
    {/exp:string:set}
    
    {exp:weblog:entries dynamic="off" weblog="the_weblog" disable="custom_fields|categories|member_data|pagination|trackbacks"}
        {exp:string:set name="the_total"}{total_results}{/exp:string:set}            
        {exp:string:set name="index_of_{entry_id}"}{count}{/exp:string:set}
    {/exp:weblog:entries}
    
    {exp:weblog:entries limit="1" weblog="the_weblog" disable="categories|member_data|pagination|trackbacks"}
         <h5>{exp:string name="index_of_{entry_id}"} of {exp:string name="the_total"}</h5>
    <p>     <ul><br />
        {exp:string name="subNav"}<br />
         </ul><br />
    {/exp:weblog:entries}

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

ExpressionEngine News!

#eecms, #events, #releases