Feature No Code Attached Yet good first issue
avatar ChristineWk
ChristineWk
24 Jul 2025

Steps to reproduce the issue

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

Expected result

Hence the request:
There should be a parameter for sorting.
Thank You.

avatar ChristineWk ChristineWk - open - 24 Jul 2025
avatar ChristineWk ChristineWk - change - 24 Jul 2025
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 24 Jul 2025
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 24 Jul 2025
avatar brianteeman
brianteeman - comment - 24 Jul 2025

It already exists

Image
avatar ChristineWk
ChristineWk - comment - 24 Jul 2025

Thank you @brianteeman
Will inform and check it.

avatar drmenzelit
drmenzelit - comment - 24 Jul 2025

The Article Order field changes the order of the articles in the list, not the order of the years in the filter

avatar brianteeman
brianteeman - comment - 24 Jul 2025

Then I misunderstood

avatar brianteeman
brianteeman - comment - 24 Jul 2025

"How can I change the sorting of the year (appears first 2011 and not 2025")?

I just checked and by default the filter appears that way

Image
avatar ChristineWk
ChristineWk - comment - 24 Jul 2025

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...

avatar ChristineWk
ChristineWk - comment - 24 Jul 2025

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)

avatar brianteeman
brianteeman - comment - 24 Jul 2025

if @Kubik-Rubik wants to submit a PR then he should do that.

avatar chmst chmst - change - 25 Jul 2025
Labels Added: Feature good first issue
avatar chmst chmst - labeled - 25 Jul 2025
avatar chmst chmst - labeled - 25 Jul 2025
avatar Klath123
Klath123 - comment - 27 Jul 2025

Hey 👋 can I work on this issue

avatar chmst
chmst - comment - 28 Jul 2025

@Klath123 sure, you are welcome :) We do not assign issues, everyone can make a PR.

avatar Aashish-Jha-11
Aashish-Jha-11 - comment - 5 Aug 2025

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...):

  1. Go to Menus → Menu Items
  2. Edit your "Archived Articles" menu item
  3. In the Archive Options tab, find "Year Filter Order"
  4. Change from "Ascending" to "Descending"
  5. Save
    This will show 2025 first instead of 2011, solving the original request.

The feature exists in default.xml as the year_order parameter and is implemented in ArchiveModel::getYears().

avatar dautrich
dautrich - comment - 5 Aug 2025

@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".

Image
avatar Sieger66
Sieger66 - comment - 5 Aug 2025

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();
    }


at https://github.com/joomla/joomla-cms/blob/5.3.2/components/com_content/src/Model/ArchiveModel.php#L149-L190

Better language strings can also built in.

avatar Aashish-Jha-11
Aashish-Jha-11 - comment - 5 Aug 2025

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.

avatar ChristineWk ChristineWk - change - 5 Aug 2025
Status New Closed
Closed_Date 0000-00-00 00:00:00 2025-08-05 12:16:43
Closed_By ChristineWk
avatar ChristineWk ChristineWk - close - 5 Aug 2025
avatar ChristineWk
ChristineWk - comment - 5 Aug 2025

Closing, see PR #45841

Add a Comment

Login with GitHub to post a comment