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
This feature is already implemented in Joomla!
The year sorting parameter already exists. To change the year order from oldest-first (2011, 2012...) to newest-first (2025,2024...):
The feature exists in default.xml as the year_order
parameter and is implemented in ArchiveModel::getYears()
.
In the default.xml is not the year_order
parameter. Show in
https://github.com/joomla/joomla-cms/blob/5.3.2/components/com_content/tmpl/archive/default.xml
https://github.com/joomla/joomla-cms/blob/6.0-dev/components/com_content/tmpl/archive/default.xml
and also in
https://github.com/joomla/joomla-cms/blob/5.3.2/components/com_content/src/Model/ArchiveModel.php#L149-190
I think you use a core-hack
@Aashish-Jha-11
To what Joomla version do you refer. I just checked on a 5.3.2, but I wasn't able to identify the "Year Filter Order".
Examplecode for Feature Request:
In /components/com_content/tmpl/archive/default.xml insert at Line #100:
<field
name="filter_field_years"
type="list"
label="JYEAR"
default="ASC"
validate="options"
>
<option value="ASC">JGLOBAL_OLDEST_FIRST</option>
<option value="DESC">JGLOBAL_MOST_RECENT_FIRST</option>
</field>
https://github.com/joomla/joomla-cms/blob/5.3.2/components/com_content/tmpl/archive/default.xml#L100
and in /components/com_content/src/Model/ArchiveModel.php change to:
/**
* Gets the archived articles years
*
* @return array
*
* @since 3.6.0
*/
public function getYears()
{
$db = $this->getDatabase();
$nowDate = Factory::getDate()->toSql();
$query = $db->getQuery(true);
$queryDate = QueryHelper::getQueryDate($this->state->params->get('order_date'), $db);
$years = $query->year($queryDate);
$filter_years = $this->state->params->get('filter_field_years' , 'ASC');
$query->select('DISTINCT ' . $years)
->from($db->quoteName('#__content', 'a'))
->where($db->quoteName('a.state') . ' = ' . ContentComponent::CONDITION_ARCHIVED)
->extendWhere(
'AND',
[
$db->quoteName('a.publish_up') . ' IS NULL',
$db->quoteName('a.publish_up') . ' <= :publishUp',
],
'OR'
)
->extendWhere(
'AND',
[
$db->quoteName('a.publish_down') . ' IS NULL',
$db->quoteName('a.publish_down') . ' >= :publishDown',
],
'OR'
)
->bind(':publishUp', $nowDate)
->bind(':publishDown', $nowDate)
->order('1 '. $filter_years);
$db->setQuery($query);
return $db->loadColumn();
}
Better language strings can also built in.
Thank you for the feedback.
I checked again and you are correct: the "Year Filter Order" parameter is not present in Joomla 5.3.2 core.
My earlier reply was based on a local modification (core-hack) or a future/experimental branch.
This feature is not yet available in the official Joomla release.
The example code provided by Sieger66 is a good starting point for a PR to add this functionality Will Implement it soon and raise a PR.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2025-08-05 12:16:43 |
Closed_By | ⇒ | ChristineWk |
It already exists