As an example from a user:
"How can I change the sorting of the year (appears first 2011 and not 2025")?
It is possible to manipulate the list in a template override ....
(Komponenten -> com_content -> archive)
But it is tedious
Hence the request:
There should be a parameter for sorting.
Thank You.
Labels |
Removed:
?
|
Labels |
Added:
No Code Attached Yet
|
Thank you @brianteeman
Will inform and check it.
The Article Order field changes the order of the articles in the list, not the order of the years in the filter
Then I misunderstood
As mentioned above, it would be possible with an override. An idea from Viktor Vogel's @Kubik-Rubik
Would it be good to be able to implement it?
`<?php $html = $this->form->yearField;
preg_match('/<option value=""[^>]*>' . Text::_('JYEAR') . '</option>/', $html, $placeholderMatch);
preg_match_all('/(\d{4})</option>/', $html, $yearMatches, PREG_SET_ORDER);
$years = [];
foreach ($yearMatches as $match) {
$years[] = [
'value' => $match[1],
'html' => $match[0],
];
}
usort($years, fn($a, $b) => $b['value'] <=> $a['value']);
$placeholder = $placeholderMatch[0] ?? '';
$optionsSorted = array_map(fn($y) => $y['html'], $years);
$selectYear = '' . "\n"; $selectYear .= ' ' . $placeholder . "\n"; $selectYear .= ' ' . implode("\n ", $optionsSorted) . "\n"; $selectYear .= '';
echo $selectYear; ?>`
Sorry, I wanted to paste the above into a code field...
Info from @Kubik-Rubik
If you want to implement this correctly in the core, you either have to intervene in the HtmlView (components/com_content/src/View/Archive/HtmlView.php) or, even better, in the corresponding model for the years (\Joomla\Component\Content\Site\Model\ArchiveModel::getYears)
if @Kubik-Rubik wants to submit a PR then he should do that.
Labels |
Added:
Feature
good first issue
|
Hey 👋 can I work on this issue
It already exists