I am looking for a way to show Joomla 4 articles in a category blog filtered by one (or more) of my custom fields. - The category blog settings in the backend seems only allow to filter by category, tag and other default article parameters. - Is filtering a blog by custom fields possible, anyways?
1 Answer
You can filter on Custom Fields via multiple ways:
- filtering via JavaScript + CSS. This will load all articles, but can CSS hide (display:none) them using some JavaScript. The articles are still there in the HTML source but just not visible.
- filtering via PHP in Joomla's Articles Model. This will load only the articles that fit to the filter state. I used this technique for a client project: I've programmed a System Plugin that overrides Joomla's Articles Model in the
populateState
method. And I programmed a Module to set the Filters. This way I was able to filter the Articles based on Filter Options using some Custom Field Fields.
There are some 3rd party extensions available that add filtering functionality to Joomla's articles:
- JL Content Fields Filter (for J3 + J4) https://extensions.joomla.org/extension/jl-content-fields-filter/
- JFilters (for J4) https://extensions.joomla.org/extension/jfilters/
-
I also suggest to check one of the suggested 3rd party extensions. No need to re-invent the wheel on that.– SakisJul 14, 2022 at 13:36
-
@pe7er could you share your System Plugin code especially on how you overwrite Joomla's Article Model in the populateState method.– cappuJul 23, 2022 at 20:23
-
I thought of writing a Plugin for this. It works fine on small projects, but may run into performance issues on larger ones. extensions.joomla.org/extension/authoring-a-content/…– cappuSep 1 at 16:07