Easy question. How do I set a limit on the total results for a page that has pagination? I have a site that displays 16 entries per-page, but would like to limit the total results to 200. Is this possible?
2 Answers
Pretty easy to do using Stash.
First, make a list of the 200 entries you want to be shown in pages. This line should have no white-space or line returns in it to prevent parsing errors.
{exp:stash:set name="entry_ids" parse_tags="yes"}{exp:channel:entries channel="pages" limit="200" disable="categories|category_fields|custom_fields|member_data|pagination" dynamic="off"}{entry_id}|{/exp:channel:entries}{/exp:stash:set}
Then load the entries for each 16 entry page as normal:
{exp:channel:entries entry_id="{exp:stash:get name='entry_ids' backspace='1'}"
parse="inward" paginate="bottom" limit="16" dynamic="off"}
{title}<br/>
{/exp:channel:entries}
-
+1 for this approach. Might be worth adding that you could disable custom fields for the first
{exp:channel:entries}
tag for a significant performance boost, as you only need theentry_id
s. Dec 1, 2012 at 19:20 -
Good suggestion Tom. I added a full disable parameter since none of the optional parts are actually needed. Dec 1, 2012 at 20:22
-
You can even add
trim="yes"
to the{exp:stash:set}
tag which will remove whitespace and allow you to format your code better. Jun 19, 2013 at 3:10
I'm not sure on how to "cap" it at 200, but you could always wrap the {paginate}
contents with a conditional to only show to a certain point (ie. 200/16 = 12.5 pages).
{exp:channel:entries
channel="name"
disable="categories|category_fields|member_data|trackbacks"
limit="16"
}
...
{paginate}
{if {current_page} < 13}
{first_page}
<li><a href="{pagination_url}" class="page-first">First Page</a></li>
{/first_page}
{previous_page}
<li><a href="{pagination_url}" class="page-previous">Previous Page</a></li>
{/previous_page}
{next_page}
<li><a href="{pagination_url}" class="page-next">Next Page</a></li>
{/next_page}
{last_page}
<li><a href="url/P192" class="page-last">Last Page</a></li>
{/last_page}
{/if}
{/paginate}
{/exp:channel:entries}
You may need to tweak the {last_page}
hard coded url.