Split custom feeds into multiple pages (pagination)
How to split a custom XML feed from a landing page into multiple pages. Your own feed template decides the parameter.
If you build your own feed through a landing page, it can get big. Really big. Some feed recipients therefore prefer to fetch it in smaller chunks instead of as one huge file, and that is called pagination: you split the feed into several pages that are fetched one at a time.
This guide explains how pagination works in custom feeds, how to set it up in your feed template, and what to watch out for when you pass the URLs on to services such as DataFeedWatch, Partner Ads, or Google Merchant Center.
The most important thing first: There is no single fixed pagination parameter for custom feeds. It is your own feed template that decides what the parameter is called and how many products are on a page. Shoporama simply passes all parameters from the URL on to the template.
How a custom feed fits together
A custom feed consists of two parts:
- A landing page that decides which products are included. You find it under Content, Landing pages.
- An XML template in your theme that decides what the feed looks like. You enter the file name in the XML filename field under the Custom XML heading when you edit the landing page.
The feed is then available at the landing page's address with .xml added to the end, for example https://dinshop.dk/mit-feed.xml.
Because it is your template that builds the content, it is also the template that has to be able to split the feed. There is no built-in pagination that kicks in by itself.
How to paginate your feed
All parameters in the URL are available in the template through the $get variable. If you fetch ?page=2, for example, the template can read the value as $get.page. You choose the name yourself: page, pagenum, offset, or something else entirely works just as well.
Below is a minimal example with 500 products per page, where the page count starts at 0:
<{$per_page = 500}>
<{$page = $get.page|default:0}>
<{$offset = $page * $per_page}>
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">
<channel>
<{foreach $landing_page->getProducts($per_page, $offset) as $product}>
<item>
<g:id><{$product->getProductId()}></g:id>
<title><{$product->getName()|escape}></title>
</item>
<{/foreach}>
</channel>
</rss>
The two numbers you pass to getProducts() are the number of products and how many to skip. Page 0 skips 0, page 1 skips 500, page 2 skips 1000, and so on. When a page returns no more products, you have reached the end.
Note: In feed templates, you must use $get. If you write $smarty.get, you get nothing, because store templates run in secure mode. If your theme runs on Smarty 2, the assignments must also be written as <{assign var="page" value=$get.page}>.
How many products should be on each page?
You decide that yourself in the template. The Number of products field on the landing page controls how the landing page is shown as a regular HTML page, but it is not used automatically in your own XML feed.
A sensible starting point is 300 to 1,000 products per page. If you have many variants, heavy descriptions, or many images per product, choose the lower number. Keep in mind that a page in the feed can contain more lines than products if your template writes one line per variant.
Fetch all pages in a script
If you need to fetch the feed from another server yourself, you can loop until a page no longer contains products:
$page = 0;
while (true) {
$url = "https://dinshop.dk/mit-feed.xml?page=".$page;
$xml = file_get_contents($url);
if (empty(trim($xml)) || stristr($xml, "<item>") === false) {
break;
}
// save or process the content here
$page++;
}
Use the tag that marks a product in your particular feed. In the example it is <item>, but it could also be <product> or something else entirely.
Watch out for the off-by-one between page 0 and page 1
The most common mistake in practice is that the feed and the recipient do not agree on where the count starts. If your template starts at 0 while the feed recipient fetches pages 1, 2, 3, and onward, the first products are missing from the feed entirely, without anyone getting an error message.
So pay attention to two things:
- The URL without a parameter corresponds to the first page, because the template typically falls back to 0. Some feed recipients fetch exactly that URL as the first page and then start at 1.
- If you would rather count from 1, subtract 1 in the template: <{$offset = ($page - 1) * $per_page}>. That way it matches recipients that always begin at page 1.
After setup, always check that the first product on the first page really is the first product in the landing page.
Speed: the feed is built automatically in the background
If you fetch the feed URL without parameters, Shoporama serves a prebuilt file. It is built automatically in the background when your products have changed, and it is also cleared when you edit the landing page itself. That is why fetching without parameters is both fast and gentle, no matter how big the feed is.
If you send parameters along, the response cannot come from that file, because you are then asking for something other than the whole feed. Those requests are therefore built on the spot. That is perfectly fine when each page only contains a portion of the catalog, but it is also the reason it does not pay to split the feed if the recipient can easily take it in one piece.
Tip: If your feed recipient does not need pagination, give them the plain URL without parameters. It is the fastest and most stable way to fetch a large feed.
Feeds that cannot be paginated
Pagination only applies to feeds you build yourself with an XML template. Two other feed types in Shoporama cannot be split, and there is no need to:
- The Google Shopping feed on a landing page (the address ending in .rss) always contains all products in the landing page and is built automatically in the background.
- Product feeds under Products, Product feeds are also built in the background and are always delivered as one complete file. Read more in the article Build your own feeds.
Pagination on landing pages and the blog
Regular landing pages and your store's blog, on the other hand, have a fixed parameter that works without you having to do anything: ?p=, where the count starts at 0.
https://dinshop.dk/min-landingsside (same as ?p=0) https://dinshop.dk/min-landingsside?p=1 (second page) https://dinshop.dk/blog?p=1 (second page of the blog)
On landing pages, the number per page is controlled by the Number of products field, up to a maximum of 500 at a time. The blog shows 10 posts per page. Only these HTML pages use ?p=. In your own XML feed, the parameter means nothing unless your template reads it itself.
Frequently asked questions
Which parameter should I use for my feed?
The one your feed template reads. If a developer made your theme, ask them, or look in the XML file named in the XML filename field on the landing page. The most common are ?page= and the combination of ?limit= and ?offset=.
I get the same content on every page. What is wrong?
Then your template does not read the parameter. Fetch two pages and compare the first products on each: if they are the same, the template ignores the pagination and writes the whole catalog every time. That has to be fixed in the template itself, as shown in the example above. Alternatively, you can simply fetch the feed without parameters as one file.
Does the page count start at 0 or 1?
Your template decides. The standard example above starts at 0, where the URL without parameters is the first page. Make sure the feed recipient begins at the same place, or the first batch of products is skipped.
How do I know I have fetched all pages?
When a page no longer contains products, there are no more. Stop the loop there. You can also have the template output the total count with $landing_page->getProductCount(), so the recipient can work out the number of pages in advance.
Do I get duplicates if a product moves to another page along the way?
It can happen if products are created or removed while you fetch the pages. The likelihood is small, but if you want to be completely sure, fetch all pages close together, or remove duplicates by product ID after combining them. Note that some feed tools do not remove duplicates themselves, and that a repeated product ID can make Meta, for example, reject the entire feed.
Can I send one complete URL to Google Merchant Center?
Yes. Send the feed URL without parameters, and you get the whole feed as one file. Pagination is only needed if the recipient explicitly asks for it.
Do I even need to split my feed today?
Rarely. Because fetching without parameters is served as a prebuilt file, even very large feeds are fast to fetch. Only split it if your recipient requires it, or if you import the feed into a system that cannot handle one large file.
Can I use the same approach for CSV or JSON?
The field on the landing page is called XML filename, but the template can output any format you like, including CSV or JSON. If you need a proper CSV or JSON feed without writing a template yourself, Product feeds is usually the easier route.
What do I do if my advertising partner cannot handle multiple URLs?
Then give them the URL without parameters, which contains the whole feed. If you do need to combine the pages on your own end, remember to remove the XML header from page two onward, so the file remains valid XML.
Need help? Contact us at support@shoporama.dk.
Related articles
Build your own custom product feeds in CSV, XML, or JSON
A guide to building your own product feeds in CSV, XML, or JSON format with Shoporama's custom feed feature.
Set up your Google Shopping feed in Shoporama
How to set up and customize the built-in Google Shopping feed in Shoporama: Google product categories, custom labels, product IDs and catalog...
Set up a Priceshape product feed
How to set up a Priceshape feed for your Shoporama store with an XML template and a landing page.
Include color and size in your Partner Ads feed
How to add color, size, and gender to your Partner Ads product feed in Shoporama using product profiles and extra fields.
Images on landing pages
How to upload images to a landing page in Shoporama and show them correctly in your theme with getImages() and getSrc().
Add a blog to your online store
A complete guide to the blog feature in Shoporama: create posts, schedule publishing, link products, optimize for search engines, and use dynamic...
Related features
Custom Feeds
Build custom product feeds in XML, JSON, or CSV. Choose fields, filter products, expand variants, and create RSS 2.0 feeds for Google Merchant Center.
Product feeds
Ready-made feeds for Google Shopping, Pricerunner, Partner Ads, Kelkoo, and TradeTracker. Or build your own custom product feeds in XML, JSON, or CSV.