Pagination of lists and long articles
  • hello,

     i don't understand how to add this page
    To implement pagination we need to add an extra page parameter to a URL, something like the following example:

    this code i put at the section.tpl or on section-cont.tpl ?
    {{ list_articles columns="10" ignore_issue="true" }}
    {{ if $gimme->current_list->count > 10 }}
    {{ if $gimme->current_list->at_beginning }}
    <div class="list-page-numbers">Page:
    {{ /if }}
    {{ if $gimme->current_list->column == 1 }}
    {{ if $gimme->current_list->row == $page }}
    <span>{{ $gimme->current_list->row }}</span>
    {{ else }}
    <a href="{{ uri options="article" }}?page={{ $gimme->current_list->row }}">{{ $gimme->current_list
    ->row }}</a>
    {{ /if }}
    {{ /if }}
    {{ if $gimme->current_list->at_end }}
    </div>
    {{ /if }}
    {{ /if }}
    {{ /list_articles }}


  • 12 Comments sorted by
  • For creating paginated list of articles (being it list of articles inside section, or search results, or whatever), you better use this kosher code from here


    (for example like this:

    {{ list_articles length="5" }}

    ...some instructions...

    {{ if $gimme->current_list->at_end }}
    PUT PAGINATION CODE HERE
    {{ /if }}
    {{ /list_articles }}

    The solution with ?page= parameter is just a workaround, and with really big lists it consumes so much resources.
    --
    Ljuba Rankovic
    Senior Front End Developer, Sourcefabric
    ljuba.rankovic@sourcefabric.org

    http://www.sourcefabric.org
    http://www.twitter.com/Sourcefabric
  • hello,
     this code work at 3.5.3 version?
  • Hi,

    no, it requires smarty 3.
    --
    Ljuba Rankovic
    Senior Front End Developer, Sourcefabric
    ljuba.rankovic@sourcefabric.org

    http://www.sourcefabric.org
    http://www.twitter.com/Sourcefabric
  • i write like this but they don't work :( why ?

    {{ list_articles length="10" }}

    <h2 class="arh">{{ $gimme->section->name }} <small>({{ $gimme->issue->name }})</small></h2>

    {{ list_articles length="10" }}
    {{ list_article_authors }}

                    <div class="post wrap">

                        <h2 class="post-title"><a href="{{ uri options="article" }}" rel="bookmark" title="{{ $gimme->article->name }}">{{ if ! $gimme->article->content_accessible }}* {{ /if }}{{ $gimme->article->name }}</a></h2>
                        <p class="post-details">{{ $gimme->article->publish_date|camp_date_format:"%e %M %Y" }} από  {{*<a href="{{ uri options="template author.tpl" }}" title="Posts by {{ $gimme->article->author->name }}">*}}{{ $gimme->article->author->name }}</a> <a href="" title="View all posts in {{ $gimme->section->name }}" rel="category tag">{{ $gimme->section->name }}</a></p>
                        <div class="category-image-block"><a title="{{ $gimme->article->name }}" href="{{ uri options="article" }}"><img src="{{$gimme->author->picture->imageurl }}"{{ uri options="image width 40"}} alt="{{ $gimme->article->image->description }}" class="woo-image thumbnail"></a></div>
    <p>{{ $gimme->article->deck|strip_tags:false|strip|escape:'html':'utf-8' }}</p>


                    </div>
    {{ /list_article_authors }}
    {{ /list_articles }}
                    <div class="more_entries">
                        <div class="alignleft"></div>
                        <div class="alignright"></div>
                        <br class="fix" />

                    </div>


    {{ if $gimme->current_list->at_end }}


    {{ $pages=ceil($gimme->current_list->count/5) }}
    {{ $curpage=intval($gimme->url->get_parameter($gimme->current_list_id())) }}
    {{ if $pages gt 1 }}
    <ul class="pagination">
        {{ if $gimme->current_list->has_previous_elements }}<li class="prev"><a href="{{ uripath options="section" }}?{{ urlparameters options="previous_items" }}">Previous</a></li>{{ /if }}
        {{ for $i=0 to $pages - 1 }}
            {{ $curlistid=$i*5 }}
            {{ $gimme->url->set_parameter($gimme->current_list_id(),$curlistid) }}
            {{ if $curlistid != $curpage }}
        <li><a href="{{ uripath options="section" }}?{{ urlparameters }}">{{ $i+1 }}</a></li>
            {{ else }}
        <li class="selected"><a href="{{ uripath options="section" }}?{{ urlparameters }}">{{ $i+1 }}</a></li>
            {{ $remi=$i+1 }}
            {{ /if }}
        {{ /for }}
        {{ if $gimme->current_list->has_next_elements }}<li class="next"><a href="{{ uripath options="section" }}?{{ urlparameters options="next_items" }}">Next</a></li>{{ /if }}
    </ul>
    {{ $gimme->url->set_parameter($gimme->current_list_id(),$curpage) }}
    {{ /if }}



    {{ /if }}
    {{ /list_articles }}
    :-(
  • hi,

    seems that you mixed few different pieces of code in one big mashup :)

    try this instead:

    <h2 class="arh">{{ $gimme->section->name }} <small>({{ $gimme->issue->name }})</small></h2>

    {{ list_articles length="5" }}

                    <div class="post wrap">

                        <h2 class="post-title"><a href="{{ uri options="article" }}" rel="bookmark" title="{{ $gimme->article->name }}">{{ if ! $gimme->article->content_accessible }}* {{ /if }}{{ $gimme->article->name }}</a></h2>
                        <p class="post-details">{{ $gimme->article->publish_date|camp_date_format:"%e %M %Y" }} από  {{ $gimme->article->author->name }}</a> <a href="{{ uri options="section" }}" title="View all posts in {{ $gimme->section->name }}" rel="category tag">{{ $gimme->section->name }}</a></p>
                        <div class="category-image-block"><a title="{{ $gimme->article->name }}" href="{{ uri options="article" }}"><img src="{{ uri options="image 1 width 40"}}" alt="{{ $gimme->article->image1->description }}" class="woo-image thumbnail"></a></div>
    <p>{{ $gimme->article->deck|strip_tags:false|strip|escape:'html':'utf-8' }}</p>

                    </div>

    {{ if $gimme->current_list->at_end }}

    {{ $pages=ceil($gimme->current_list->count/5) }}
    {{ $curpage=intval($gimme->url->get_parameter($gimme->current_list_id())) }}
    {{ if $pages gt 1 }}
    <ul class="pagination">
        {{ if $gimme->current_list->has_previous_elements }}<li class="prev"><a href="{{ uripath options="section" }}?{{ urlparameters options="previous_items" }}">Previous</a></li>{{ /if }}
        {{ for $i=0 to $pages - 1 }}
            {{ $curlistid=$i*5 }}
            {{ $gimme->url->set_parameter($gimme->current_list_id(),$curlistid) }}
            {{ if $curlistid != $curpage }}
        <li><a href="{{ uripath options="section" }}?{{ urlparameters }}">{{ $i+1 }}</a></li>
            {{ else }}
        <li class="selected"><a href="{{ uripath options="section" }}?{{ urlparameters }}">{{ $i+1 }}</a></li>
            {{ $remi=$i+1 }}
            {{ /if }}
        {{ /for }}
        {{ if $gimme->current_list->has_next_elements }}<li class="next"><a href="{{ uripath options="section" }}?{{ urlparameters options="next_items" }}">Next</a></li>{{ /if }}
    </ul>
    {{ $gimme->url->set_parameter($gimme->current_list_id(),$curpage) }}
    {{ /if }}

    {{ /if }}
    {{ /list_articles }}

    --
    Ljuba Rankovic
    Senior Front End Developer, Sourcefabric
    ljuba.rankovic@sourcefabric.org

    http://www.sourcefabric.org
    http://www.twitter.com/Sourcefabric
  • hello
    i copy paste this code but i don't see the page number.
  • Well
    a) Do you have more than 5 articles there? 
    b) in your page's source there is still this code 

    <div class="more_entries">
        <div class="alignleft"></div>
        <div class="alignright"></div>
        <br class="fix" />
    </div>

    what is it used for? check again if you have right code on right place
    --
    Ljuba Rankovic
    Senior Front End Developer, Sourcefabric
    ljuba.rankovic@sourcefabric.org

    http://www.sourcefabric.org
    http://www.twitter.com/Sourcefabric
  • i remove this code 
    <div class="more_entries">
        <div class="alignleft"></div>
        <div class="alignright"></div>
        <br class="fix" />
    </div>

    a) Do you have more than 5 articles there?
    no i have only 5 articles

    and i have this now
    <h2 class="arh">{{ $gimme->section->name }} <small>({{ $gimme->issue->name }})</small></h2>

    {{ list_articles length="5" }}

                    <div class="post wrap">


     
     <h2 class="post-title"><a href="{{ uri options="article" }}" rel="bookmark" title="{{ $gimme->article->name }}">{{ if ! $gimme->article->content_accessible }}* {{ /if }}{{ $gimme->article->name }}</a></h2>
                        <p class="post-details">{{ $gimme->article->publish_date|camp_date_format:"%e %M %Y" }} από  {{ $gimme->article->author->name }}</a> <a href="{{ uri options="section" }}" title="View all posts in {{ $gimme->section->name }}" rel="category tag">{{ $gimme->section->name }}</a></p>
                        <div class="category-image-block"><a title="{{ $gimme->article->name }}" href="{{ uri options="article" }}"><img src="{{ uri options="image 1 width 40"}}" alt="{{ $gimme->article->image1->description }}" class="woo-image thumbnail"></a></div>
    <p>{{ $gimme->article->deck|strip_tags:false|strip|escape:'html':'utf-8' }}</p>

                    </div>

    {{ if $gimme->current_list->at_end }}

    {{ $pages=ceil($gimme->current_list->count/5) }}
    {{ $curpage=intval($gimme->url->get_parameter($gimme->current_list_id())) }}
    {{ if $pages gt 1 }}
    <ul class="pagination">
        {{ if $gimme->current_list->has_previous_elements }}<li class="prev"><a href="{{ uripath options="section" }}?{{ urlparameters options="previous_items" }}">Previous</a></li>{{ /if }}
        {{ for $i=0 to $pages - 1 }}
            {{ $curlistid=$i*5 }}
            {{ $gimme->url->set_parameter($gimme->current_list_id(),$curlistid) }}
            {{ if $curlistid != $curpage }}
        <li><a href="{{ uripath options="section" }}?{{ urlparameters }}">{{ $i+1 }}</a></li>
            {{ else }}
        <li class="selected"><a href="{{ uripath options="section" }}?{{ urlparameters }}">{{ $i+1 }}</a></li>
            {{ $remi=$i+1 }}
            {{ /if }}
        {{ /for }}
        {{ if $gimme->current_list->has_next_elements }}<li class="next"><a href="{{ uripath options="section" }}?{{ urlparameters options="next_items" }}">Next</a></li>{{ /if }}
    </ul>
    {{ $gimme->url->set_parameter($gimme->current_list_id(),$curpage) }}
    {{ /if }}

    {{ /if }}
    {{ /list_articles }}
  • Pagination won't appear if it is not needed. Add sixth article and it should appear (list is limited to 5 results, only after that next and previous items exist)
    --
    Ljuba Rankovic
    Senior Front End Developer, Sourcefabric
    ljuba.rankovic@sourcefabric.org

    http://www.sourcefabric.org
    http://www.twitter.com/Sourcefabric
  • i have more than 20 article but they don't see nothing
  • But it won't work on Newscoop 3.5.3, it uses smarty 3 functions, and Smarty 3 is used in Newscoop versions starting with  3.6.
    Consider upgrading to 4.0-beta2, it brings a tone of new features, or solve pagination differently (there is one example in Newscoop Cookbook http://en.flossmanuals.net/newscoop-3-cookbook-3-5-2/pagination/)
    --
    Ljuba Rankovic
    Senior Front End Developer, Sourcefabric
    ljuba.rankovic@sourcefabric.org

    http://www.sourcefabric.org
    http://www.twitter.com/Sourcefabric
  • how to update Newscoop 3.5.3 to versions starting with  3.6.