55

You are probably not using this within a craft.entries loop. Position it inside a loop or set custom parameters for your prev and next elements: {# Set parameters for prev/next elements list #} {% set params = craft.entries.section('blog').order('title asc') %} {# Get the prev/next elements #} {% set prevEntry = entry.getPrev(params) %} {% set nextEntry = ...


19

You can set the prev.url at the top of the template, for example: {% set criteria = {section: 'blog', order: 'postDate'} %} {% set prev = entry.getPrev(criteria) %} Add a link if prev is available: {% if prev %} <a href="{{ prev.url }}">{{ prev.title }}</a> {% endif %}


15

{{ paginate.nextUrl }}?q={{ query }} did the trick with this setup.


12

Sure, http://buildwithcraft.com/docs/templating/paginate {% paginate craft.entries.section('blog').limit(10) as entries %} <a href="{{ paginate.firstUrl }}">First Page</a> {% if paginate.prevUrl %}<a href="{{ paginate.prevUrl }}">Previous Page</a>{% endif %} {% for page, url in paginate.getPrevUrls(5) %} <a ...


10

I ran into this today. I thought craft.request.path used to include the pagination page number but it doesn't appear to anymore. Maybe it was always like this though. Regardless, this is how I'm now handling it: {% cache globally using key craft.request.path ~ '/p' ~ craft.request.getPageNum %} ... {% endcache %}


9

Hey So here is what i came up with, curious if anyone has a more streamlined approach. https://gist.github.com/keithmancuso/17619fc405a621b4a11e {% if craft.request.isAjax %} {% set layout = "_ajaxLayout" %} {% else %} {% set layout = "_layout" %} {% endif %} {% extends layout %} {% set limit = 10 %} {% set params = { section: 'news', limit: ...


9

The paginate.totalPages variable will give you the total number of pages that are generated by the paginate tag. So you can wrap your display of pages around a conditional that checks to see if this is greater than 1. {% if paginate.totalPages > 1 %} {# output current pages and pagination navigation here #} {% endif %} More details, including a ...


9

In most Craft projects I do I'll create a pagination include file so anything I need that requires pagination, I can just include that and I get the same pagination pattern anywhere within my site when I need it. While you do have to set the country attribute with each link, sometimes it might get a little tedious to do this manually or you may expand your ...


7

There's an offset parameter that allows you to skip the first entries from your ElementCriteriaModel. You would set up two nearly identical ElementCriteriaModels, one exclusivly for your featured entry, using the first() method to only query for the first entry, and to the second one you'd add offset(1) as a parameter, to get all the other entries for your ...


7

You can only pass an object or an ElementCriteriaModel (what you get when you type 'craft.entries') into getNext() and getPrev(). Calling find() on an ElementCriteriaModel, as I'm doing in my code, turns it into an actual array of entries, which is not something getNext() and getPrev() can work with. So changing the first line to this will work: {% set ...


6

Thanks to Kieth for posting an ajax solution. I just wanted to expand on it a little bit to figure out when we are at the end of the entries etc so we can hide loading more buttons etc. Here is what I did. In my example I am only loading 2 entries for each click so I'm setting the count to 2, and then incrementing the count on each click by 2. Here I am ...


6

The easiest way would be to check craft.request.urlReferrer and see if they just came from the entry index page. If so, provide a link to send them back. {% set referrer = craft.request.urlReferrer %} {% set indexBaseUrl = url('articles') %} {% if referrer and referrer|slice(0, indexBaseUrl|length) == indexBaseUrl %} <a href="{{ referrer }}">Go ...


6

Try using this (completely untested): {% if paginate.prevUrl %} <a href="{{ paginate.prevUrl }}?{{ craft.request.getQueryStringWithoutPath() }}">Previous Page</a> {% endif %} {% if paginate.nextUrl %} <a href="{{ paginate.nextUrl }}?{{ craft.request.getQueryStringWithoutPath() }}">Next Page</a> {% endif %} Update: The ...


6

The without filter converts your ElementCriteriaModel into an array of entry models (the same as find() does). But that array won't work with paginate, as explained in the docs: This parameter needs to be an actual ElementCriteriaModel object; not an array of elements. So don’t call find() on the object. So you need to query for the entries you're after ...


6

As I already wrote in my comment 3 days ago something like this should work {% paginate craft.entries.section('mySection').limit(10) as pageInfo, pageEntries %} {% for page, url in pageInfo.getPrevUrls(3) %} <a href="{{ url }}">{{ page }}</a> {% endfor %} <span class="current">{{ pageInfo.currentPage }}</span> {% for page, url ...


5

To get this working, you will need to find a way to continue passing all of your form’s values to each of the additional pages. There are a few ways you could do that, but the easiest and best option is to change your search form’s method attribute to "get" rather than "post". <form method="get"> (Side note: there’s no need to add action="" – the ...


5

You have your {% for %} and {% paginate %} tags in the reverse order. You need to wrap the loop and the pagination URLs with the {% paginate %} tag pair: {% paginate craft.entries.section('houseRules').limit(1) as entries %} {% for entry in entries %} <div class="rule-content"> <article> {# Content is ...


5

I don't know if there's a route way to handle this, but you could do a conditional on the craft.request method getPageNum() like so: {% if craft.request.getPageNum == 1 %} <!-- Header for the home page --> {% else %} <!-- Header for pagination pages --> {% endif %}


5

You can limit the prev/next links to only show entries with the same tags using the relatedTo param: {% set params = { section: 'databytes', order: 'title', relatedTo: { targetElement: entry.tagsFieldHandle, field: 'tagsFieldHandle' } } %} That might do the trick, but it may lead to inconsistent prev/next page links, because you can have more ...


5

You can only modify a craft.entries criteria model with a field (→ Add custom element criteria attribute without a field type?). So what you have to do is to create a new custom field type with your plugin, and add such a field to the entry types you want to filter. {% set entries = craft.entries.section('mySection').country('germany') %} With that ...


5

You could use Twig's Slice function. {% set firstTwo = paginatedEntries|slice(0,2) %} {% set lastFour = paginatedEntries|slice(2,4) %} Then loop over firstTwo for your first items. {% for entry in firtTwo %} {# Show first 2 entries #} {% endfor %} Loop over lastFour for your final items. {% for entry in lastFour %} {# Show next 6 articles #} {% ...


5

You need to set a limit on your element query, so Craft knows how many entries you want per page: {% paginate craft.entries.section('newsBlog').limit(1) as pageInfo, pageEntries %} If you don't set a limit, {% paginate %} will return a single page with all entries, because the default value for limit in Craft 3 is null (in Craft 2, the default was 100).


5

project.images is an array because you are eager-loading the images. Since you’re only loading one project entry, you’re not actually gaining anything by eager-loading the images (or category), though. In fact, you’re actually slowing things down a bit. Eager-loading does come with a little bit of overhead, so you should only use it when you’ve got an “n+1” ...


4

I would use Craft's built in paginate tag. You just add the page number (p2, p3, p4, etc.) to the end of the url in your ajax call and output the template like this: {% paginate craft.entries.section('blog').limit(10) as entries %} {% for entry in entries %} <h1>{{ entry.title }}</h1> {{ entry.body }} {% endfor %} {% ...


4

To do this, you would need to use getPrev() and getNext() on the related entries’ template. The trick is telling getPrev() and getNext() to use the order you defined in the source entry’s Entries field. So first, you will need to get that source entry. If you only have a single entry in your structure section that has one of these Entries fields, that ...


4

This is not something built into Craft, but you could accomplish this with a plugin. You could have it run during your plugin's init function. On each page load, it would take the current page and load it into a currentUrl session variable. Then when you went to another page, the previous page url would move from currentUrl to a prevUrl session variable, and ...


4

Twig (and all php) is processed server-side before javascript even gets initiated. And once the page renders in the browser there no way to interact directly with twig. The only two options that you have is to either 1) reload the page or 2) request a page segment via ajax. I would opt for the later in this case. To do this, you could either listen for an ...


4

Good starting point: https://craftcms.com/docs/templating/paginate If you also want display '...' instead of the whole list of page numbers, you can do something like this: {% if pageInfo.totalPages > 1 %} <div class='blogPostList__pagination'> {% if pageInfo.prevUrl %}<a href='{{ pageInfo.prevUrl }}' class='blogPostList__pagination__prev'&...


4

Instead of using pagination, you might try creating a custom route using tags for year/month/day. Those tags will be available as variables in the template that you can use to load that days entries and generate the nav for next/previous day, etc. Using ajax the uri won't be visible to the user anyway. {% set postDate = year ~ '-' ~ month ~ '-' ~ day %} {% ...


4

The probably more elegant way to handle this is to not use the without filter at all and simply list the categories you want to exclude prefixed with not. {% set categories = craft.categories({ group: 'location', slug: [ 'and', 'not berlin', 'not amsterdam', ], limit: null, }) %} {% set entries = craft.entries....


Only top voted, non community-wiki answers of a minimum length are eligible