Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination #58

Open
dmpour23 opened this issue Oct 8, 2016 · 3 comments
Open

Pagination #58

dmpour23 opened this issue Oct 8, 2016 · 3 comments

Comments

@dmpour23
Copy link

dmpour23 commented Oct 8, 2016

Hi is their a way to include pagination i.e top 5 -10 posts /news.

@jandecaluwe
Copy link
Owner

Yes, by using the features of the Jinja2 templating language on the site data structure that is made available to it automatically.

@jshaffstall
Copy link
Contributor

Can you point me in the right direction for pagination? For example, I have an index.md that gets a list of all the files in the current directory. I'd like that list to be displayed in paginated form, which suggests Urubu generating index.md, index2.md, index3.md, etc, depending on how many items are shown on each page.

Does Urubu do that?

@jshaffstall
Copy link
Contributor

If someone else comes here looking for pagination, I have a fork that does it in the way I needed: https://github.com/jshaffstall/urubu

It may not play well with all of Urubu's features, since I'm not currently using all of them. But it works for my use case. The changes are entirely in processors.py, if you want to update your copy of Urubu in site-packages.

To generate paged index files, add the following front matter:

items_per_page: 5
items_index: this

Change items_per_page to suit your needs. This will generate enough index.html variants (index.html, index2.html, index3.html, etc) to display all the items in chunks of items_per_page.

Each page will get some new attributes added to help with templates.

numpages - the number of total pages generated
thispage - the page number of this page in the chain
prevpage - the previous page in the chain
nextpage - the next page in the chain
pages - a list of page numbers and page objects

As an example of template navigation using these, this is what I used for mine:

      {% if this.numpages %}
			            <div class="block-27">
			              <ul>
      {% if this.prevpage %}
			                <li><a href="{{this.prevpage.url}}">&lt;</a></li>
      {% endif %}
      {% for page in this.pages %}
      {% if page.pagenum == this.thispage %}
			                <li class="active"><span>{{page.pagenum}}</span></li>
      {% else %}
			                <li><a href="{{page.page.url}}">{{page.pagenum}}</a></li>
      {% endif %}
      {% endfor %}
      {% if this.nextpage %}
			                <li><a href="{{this.nextpage.url}}">&gt;</a></li>
      {% endif %}
			              </ul>
			            </div>
      {% endif %}

You can also use this for non-index files if you have a suitable filter that will generate the items you want to display. Use this front matter instead:

items_per_page: 5
items_filter: mysteries narrative categories

Where the first word in the items_filter attribute is the name of the filter function, and the remaining words are parameters to that filter function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants