Search

Hi,

I'm trying to make simple pagination in my blog. Now I have 7 entries.

In data sources I set:

 Paginate results, limiting to 6 entries per page. Return page 1

And this is code:

<xsl:template name="load-more-posts">
  <a href="#" class="more-posts-button">Load more posts</a>
</xsl:template>

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...

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.

@hub33k, are you wanting to load more results without a page-load or just link to the next page of results?

If the latter, maybe you could look at pjax or djax.

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:

  1. Make sure you don't have a require parameter that stops the Data Source execution.
  2. Make sure you have set the page number to {$url-page:1}.
  3. Make sure you have system: pagination included in your XML output.

In your template:

  1. Make sure you have added the page parameter to your link, e. g. example.com/?page=2.
  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" />
    
  3. 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.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details