Load More Pagination for Joomla Blog + YOOtheme Pro
Summary
A large blog on Joomla with YOOtheme Pro constructor displayed articles through the Custom Articles element. This source had two unpleasant features: built-in pagination did not connect to it, and it had an undocumented ceiling on the number of materials. As a result, either all hundreds of articles were displayed as a single 'sheet', or only the first N were shown — with the rest being inaccessible. I wrote a Joomla plugin that loads articles in portions via AJAX button 'Load more' directly from the database, bypassing the YOOtheme source. The plugin survives template updates because it is a regular Joomla extension, not a template modification. I released it as open source on GitHub.
Technology Stack
| Technology | Role |
|---|---|
| Joomla 6 | CMS the plugin runs in |
| YOOtheme Pro | Page builder that renders articles through Custom Articles |
| PHP | Server side of the plugin, Ajax endpoint, SQL |
| Javascript (ES6) | Client-side Load more button and card rendering |
| MySQL | Direct article queries from #__content |
| com_ajax | Standard Joomla Ajax mechanism |
| GitHub | Repository and release with the installable ZIP |
Context and Task
There is a site where articles are displayed in a blog format through YOOtheme Pro — a popular constructor for Joomla. The display is made with the Custom Articles element: it takes articles from a selected category and lays them out in a grid.
The problem arose when there were many articles — several hundred. It was necessary for the reader to be able to scroll through everything: from the first to the oldest article. Not to be lazy and scroll to the end, but to actually get access to any publication.
Then came the classic conflict of 'want to vs can':
- Wanted a simple 'See more' / 'Load more' button that, upon clicking, loads the next 12–15 card items without reloading the page.
- Turned out, the Custom Articles source in YOOtheme has no built-in pagination at all. The 'Pagination' element in the constructor works only with the source
Page → Articles(standard Joomla blog), and it does not connect toCustom Articlesat all.
The first solution that came to mind was to set the source limit to Number = 12, to show the first 12. But this is a dead end: the rest of the articles then disappear from the user's view forever.
Then I tried to 'show everything' — set a giant limit. The result was predictable and sad:
- hundreds of cards were dumped onto the page at once;
- the page swelled to ~1 MB of HTML;
- each card pulled an image with
srcsetfor several resolutions; - loading speed dropped, and this was all for 'just show everything'.
Moreover, it turned out that even with limit = 999999999, YOOtheme still does not return everything: the Custom Articles source has an internal undocumented ceiling on the number of materials, which the Limit field does not bypass. That is, the constructor's built-in means cannot solve the task at all.
Conclusion: a custom pagination mechanism is needed, which works around the YOOtheme source.
Why a Plugin, Not a Template Modification
Here I faced a choice: fix 'inside' YOOtheme or write separately.
Modifying the template was immediately ruled out for one reason: YOOtheme Pro updates, and updates overwrite template files. Applying custom modifications inside means signing up for the fact that after each update everything will reset and needs to be fixed again. This is not an engineering approach.
Therefore, the solution is a regular Joomla plugin. It lives in its own extension folder, does not touch template files, and calmly survives any YOOtheme updates. This is the same principle by which all normal Joomla extensions work.
The logic is as follows: the first N articles are still drawn by YOOtheme (as before), and everything beyond this is loaded by my plugin in portions via AJAX.
Architecture of the Solution
The plugin consists of three parts.
1. Server-side (PHP)
A Joomla plugin of the content group that registers an Ajax endpoint through the standard mechanism com_ajax. For each request, it:
- accepts parameters
offset,limit,catid(and optionally the sort field and direction); - goes directly to the
#__contenttable (Joomla articles); - selects published articles of the required category, whose publication date has already arrived;
- sorts (by default — by publication date, new ones on top);
- returns a JSON array of cards: title, teaser, image (intro image), date, link.
The key is that the data is taken directly from the database through the Joomla API, not through the Custom Articles source. This bypasses the lack of pagination and the aforementioned internal ceiling of YOOtheme.
2. Client-side (JavaScript)
The script yootheme_pagination.js, which the plugin only attaches to the necessary page. On the DOMContentLoaded stage, it:
- finds the grid of cards on the page (
a.uk-card[href^="/blog/"]); - counts how many cards YOOtheme has already rendered — this is the starting
offset; - adds a button under the grid with the theme classes
uk-button uk-button-secondary(the same styling as all buttons on the site); - on click, makes a
fetchto the endpoint and again adds a portion of cards; - when articles run out — removes the button.
The cards are rendered in the same DOM template as YOOtheme cards (el-item, uk-card-primary, uk-card-media-top, el-title, el-meta), so the visually loaded articles are indistinguishable from the original ones.
3. Settings
Everything that can differ between sites is moved to plugin parameters:
Category ID— blog category;Articles per page— portion per click;Order field/Order direction— sort field and direction;Menu ItemID (Blog)— ID of the menu item for correct article links;Load more button text— button text;Date language— language of months in dates (en / ru).
What I Did Step-by-Step
Step 1. Figured Out How the Source Actually Works
First, not guessing but looking deep inside. Went into the YOOtheme constructor and pulled out the actual configuration of the 'Blog' template: where exactly the grid of articles lies, what its source is, and what arguments the source has. It turned out the source is customArticles with a set of fields like catid, offset, limit, order.
This gave the main thing: the source internally supports offset and limit, but the constructor does not build pagination on it. This means the loading mechanism can be hung parallel to the source, without modifying the block.
Step 2. Ensured There Are No Built-in Solutions
Checked the 'Pagination' element in the constructor: it is marked as disabled and does not connect to the Custom Articles source — this was confirmed both in the template configuration and in the documentation. The hope of 'enabling ready-made' was gone. Plus, the ceiling on the number of materials was discovered.
Step 3. Checked Data in the Database
Connected to the database and looked at the real data: how many articles in total in the category, what fields they have, how the intro image is stored. Here another nuance was found: in Joomla, the image image_intro is stored with a service tail like images/blog/633.webp#joomlaImage://local-images/.... This tail needs to be cut off to #, otherwise the card will have a broken URL. This became a separate mini-task in the plugin.
Step 4. Wrote the Plugin and Attached It to Joomla 6
The most capricious part — correct operation of the Ajax endpoint in Joomla 6. The nuance is how Joomla 6 loads plugins: there exists a namespace model and a legacy fallback. The final working combination:
- the plugin file is located at
plugins/content/{element}/{element}.php; - the plugin class is named according to the legacy convention
Plg{group}{element}; - the handler method is named
onAjax{Element}; com_ajaxwraps the plugin response in a nested structure `{
