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.

pagination - if last page, do something else

October 26, 2010 10:16am

Subscribe [3]
  • #1 / Oct 26, 2010 10:16am

    Ross1988

    59 posts

    Hopefully I’m being dense but I can’t seem to get this to work

    I have a system that shows a bunch of Weblog entries with a specific status, paginated in groups of 5.

    If the user is on the last page, I want another list of entries to be displayed with a different status.

    is this even possible?

    I’ve looked for “last_page” or similar variable but I can’t find anything

    mock code is

    {exp:weblog:entries weblog="foo" status="bar" limit="5" paginate="both"}
    {paginate}{paginate_links}{/paginate}
    
    {title}
    
    <!-- so either -->
    {if last_page==true}
      {exp:weblog:entries weblog="foo" status="NOT-bar"}
      {title}
      {/exp:weblog:entries}
    {/if}
    
    
    {/exp:weblog:entries}

    in short - need to determine if the last page of pagination is reached, then display another set of results from a weblog

    thanks

  • #2 / Oct 26, 2010 11:18pm

    Sue Crocker

    26054 posts

    Hi, Ross.

    http://expressionengine.com/legacy_docs/modules/weblog/pagination_page.html

    Take a look at the comments on the page. See if the code by Hop Studios works for you.

  • #3 / Oct 27, 2010 5:29am

    Ross1988

    59 posts

    Hi Sue,

    I forgot to mention I had tried that, but I need something to the effect of

    {paginate}
    {if "{current_page}" == "{total_pages}"}
        {assign_variable:foo="bar"}
    {/if}
    {/paginate}
    
    <!-- then some where else on the page -->
    {if foo=="bar"}
    <!-- do something -->
    {/if}

    unfortunately as per the docs, EE var’s assigned in this way are just textual substitutes.

    I found a similar sounding problem @ http://ellislab.com/forums/viewthread/91192/ but no solution was achieved

    i’ve tried

    {paginate}
    {if "{current_page}" == "{total_pages}"}
        <?php $last_page= TRUE; ?>
    {/if}
    {/paginate}
    
    // then
    
    <?php if($last_page) { ?>
    <!-- do something -->
    <?php } ?>

    using both output and input PHP parsing but to no avail. http://www.thenestedfloat.com/articles/mixing_php_variables_with_expressionengine_template_tags seems to think this approach works though?

    the problem i found was that the conditional executed regardless, which to me suggests that the

    {if "{current_page}"=="{total_pages}"} <?php /*code*/ ?> {/if}

    is being ignored.

    any further ideas?

    thanks

  • #4 / Oct 27, 2010 3:43pm

    Ingmar

    29245 posts

    Try to put the actual code in your conditional (or use an embed, perhaps a snippet):

    {if current_page == total_pages}
        <?php do something -->
    {/if}
  • #5 / Oct 27, 2010 4:34pm

    Ross1988

    59 posts

    Try to put the actual code in your conditional (or use an embed, perhaps a snippet):

    {if current_page == total_pages}
        <?php do something -->
    {/if}

    Yes, that does work but not for the purpose I need I’m afraid.

    perhaps you could try an example.

    Looking at the parse order, it would seem what I’m trying to do can’t be done, or I’m approaching it from the wrong angle.

    I have resolved it in a different way, by using

    {if current_page == total_pages} <a href="http://{path=group/template}">View Everything Else</a>{/if}

    but ideally would have liked the “Everything Else” to be on the last page of the pagination. (But NOT within the {pagination}, on a separate part of the page - hence the use of a conditional variable.

    If anyone has some spare time and would like to take a look at my setup, here it is with site specific code stripped out:

    <?php
    /*
     * template group: listings
     * template : view
     * weblog : events
     * entries : 15
     * PHP Parsing Enabled. Try with Input and Output.
     */
    ?>
    
    {exp:weblog:entries weblog="events" status="Open" limit="5" paginate="both"}
    
    {paginate}
    (Viewing page {current_page} of {total_pages}) {pagination_links}
    
    {if "{current_page}" == "{total_pages}"}
        <?php $is_last_page = true;  /* It's the last page ! */?>
    {/if}
    
    {/paginate}
    
    <div>
    <h2>{count} {title}</h2>
    <p>{summary}<br />
    </div></p>
    
    <p>{/exp:weblog:entries}</p>
    
    <p><?php if ($is_last_page) { /* It's the last page…let's show the other entries */ ?><br />
    {exp:weblog:entries weblog="events" status="Closed"}<br />
    These entries have status "Closed".</p>
    
    <p><div></p><h2>{count} {title}</h2>
    <p>{summary}<br />
    </div></p>
    
    <p>{/exp:weblog:entries}</p>
    
    <p><?php } ?>


    See what results you get.

    makes good sense to me

  • #6 / Oct 27, 2010 4:54pm

    Ingmar

    29245 posts

    Seeing as how you found a solution, let me move this to the CodeShare Corner so we don’t have to close it.

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

ExpressionEngine News!

#eecms, #events, #releases