[SOLVED] Pagination
This is an open discussion with 19 replies, filed under XSLT.
Search
In your datasource, you should have an option to choose pagination as one of the outputs, make sure it's selected.
That should append some information in your datasource which would allow you to plug in the DS pagination utility mentioned. This information would include, current page, total pages etc.
If you still cannot find it, I'll send some screenshots. I assume you're using the latest version of Symphony correct?
If you just want to add a link at the bottom to the next page, make sure that link passes the desired page number, e. g. example.com/?page=2
. In your Data Sources, that GET parameter will be available as $url-page
, so you can replace your static page number 1
in the editor with {$url-page}
and your content will update based on the given number in the URL.
You could also define a fallback, in case there is no parameter given in the URL like so: {$url-page:1}
(where 1
calls the first page, if $url-page
is empty).
If you need something more advanced have a look here: https://github.com/hananils/kit/blob/master/pagination.xsl. It's an updated version of Nick's template.
@gunglien, I'm using Symphony 2.3.6
@Nils, the thing is that I don't know how to do that. In DS in Required URL Parameter
I enter $url-page
and what should I do next? Now when I go to blog page there are no entries but when I type in URL example.com/blog/?page=1
I got my 6 entries. When I type example.com/blog/?page=2
there are entries from page 1.
In DS in Required URL Parameter I enter $url-page and what should I do next?
Use the data source editor’s Return page
field under “Sorting and Limiting”.
Great, it works (Return page: {$url-page:1}
). But when I go to example.com/blog
there are no entries.
If you have anything in the “Required URL Parameter” field, remove it.
OK, last question: how to make this link work?
<xsl:import href="../utilities/vendor/pagination.xsl"/> <xsl:template name="load-more-posts"> <a href="#" class="more-posts-button">Load more posts</a> </xsl:template>
If you still have set $url-page
to be a required parameter, remove that setting and see if that changes the output.
When I click Load more posts
I want to display on the new page results.
E. g.
I'm on example.com/blog
and I have 6 entries, now I want to load more posts and I click button Load more posts
and on the new page I have these posts.
example.com/blog
- main page
example.com/blog/?page=2
- next page
example.com/blog/?page=x
- etc.
See Nils’ example usage if you’re using that version.
Hopefully you will be able to build your next/previous links using the XML available to your page, which you can see by appending ?debug
to the URL in-browser.
Hmmm, in XML should I have <pagination>
element?
It depends on what you called your pagination data source.
A few things for you to check in your Data Source:
- Make sure you don't have a require parameter that stops the Data Source execution.
- Make sure you have set the page number to
{$url-page:1}
. - Make sure you have
system: pagination
included in your XML output.
In your template:
- Make sure you have added the
page
parameter to your link, e. g.example.com/?page=2
. Make sure you dynamically set the correct next page using the
pagination
element in your XML. It should look something like this:<pagination total-entries="6" total-pages="1" entries-per-page="6" current-page="1" />
Or alternatively make use of one of the available pagination templates.
I added system: pagination
:
<pagination total-entries="8" total-pages="2" entries-per-page="6" current-page="1" />
Try this:
<a href="{$blog}/?page={/path/to/your/pagination/@current-page + 1}" class="more-posts-button">Load more posts</a>
You can also just try out if your Data Source works by changing the URL in your browser, e. g. example.com/?page=2
, example.com/?page=3
…
Great! Now it works. Thanks for your time guys :)
Create an account or sign in to comment.
Hi,
I'm trying to make simple pagination in my blog. Now I have 7 entries.
In
data sources
I set:And this is code:
I'd like to load more posts but I have no idea how to do that. I think that I need DS pagination.
Please help...