Pagination

All FLEX loops allow for pagination. All loops by default are set to 100 per page which is the max items allowed per page. In order to use pagination, you must declare pagination before the loop you would like to paginate.

Once Pagination is set using the pagination function. No other pagination is available within flex. You can only have one pagination per page.

Example:

{% pagination template(20) %}
{% define $x = 1 %}
{% loop template('tpl_recipe', 'id', 'desc') %}

From the example above, you can see that we call {% pagination template %}. This tells FLEX to setup pagination for the template loop. If we are doing pagination on a category or product loop, we would change the word template to the proper loop. The following loops support pagination:

  • Search
  • Category
  • Product
  • Template

After pagination has been called in FLEX and the loop has been completed, we can call the html for the default pagination.

Example:

{% pagination template(20) %}
{% define $x = 1 %}
{% loop template('tpl_recipe', 'id', 'desc') %}
<div class="list_layout {% if $x == 2 %} odd {% define $x = 1 %} {% else %} even {% increment($x) %} {% endif %}">
<h3><a href="{tpl_recipe.page_url}">{tpl_recipe.page_name}</a></h3>
<a href="{tpl_recipe.page_url}"><img src="{tpl_recipe.attr_recipe_image}" /></a>
<p>{tpl_recipe.page_content_15}...</p>
<a href="{tpl_recipe.page_url}">&raquo; Read More</a>
</div>
{% endloop tpl_recipe %}
<div class="clear:both;"></div>
{% default_pagination("Prev", "Next", 5) %}

From the example above, you can see that we call {% default_pagination("Prev","Next",5) %}. The first parameter is the Text you would like to appear in the Previous Link. The second parameter is the Text you would like to appear in the Next Link. The last parameter is how many pages on either side of the current page the user is viewing. For example, by specifying 5, you will see 1,2,3,4,5,6,7,8,9,10. To see less page numbers, specify a lower count such as 2 or 3. This value can range from 1 to 15. Anything larger than 15 will default to 15.

You can see from the example above, template has been defined as 20. This will return 20 results per page up to 100 per page. If you wanted the user to be able to specify this value, simply add the value view in the url.

For example, mysampleleadcommerce.com/shirts/women?page=6&view=15.

Example:

{% pagination template(20) %}
{% define $x = 1 %}
{% loop template('tpl_recipe', 'id', 'desc') %}

If only 1 page exists, default_pagination will return an empty <ul> tag.

Output Tag Description
{pagination_total_items} Total of items returned
{pagination_total_pages} Total number of pages
{pagination_current_offset_end} End number of result set
{pagination_current_offset_start} Start number of result set

Start your free, no-risk trial today.