Skip to content

Commit

Permalink
[FEATURE] Add config to sort news in seo sitemap (#2620)
Browse files Browse the repository at this point in the history
Related: #2618
  • Loading branch information
kanow authored Feb 15, 2025
1 parent 4230e9c commit d2c107e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Classes/Seo/NewsXmlSitemapDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function generateItems(): void
$pids = !empty($this->config['pid']) ? GeneralUtility::intExplode(',', $this->config['pid']) : [];
$lastModifiedField = $this->config['lastModifiedField'] ?? 'tstamp';
$sortField = $this->config['sortField'] ?? 'datetime';
$sortDirection = $this->config['sortDirection'] ?? 'ASC';
$forGoogleNews = $this->config['googleNews'] ?? false;

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
Expand Down Expand Up @@ -126,7 +127,7 @@ public function generateItems(): void
->setFirstResult($page * $this->numberOfItemsPerPage)
->setMaxResults($this->numberOfItemsPerPage);

$rows = $queryBuilder->orderBy($sortField, $forGoogleNews ? 'DESC' : 'ASC')
$rows = $queryBuilder->orderBy($sortField, $forGoogleNews ? 'DESC' : $sortDirection)
->executeQuery()->fetchAllAssociative();

foreach ($rows as $row) {
Expand Down
2 changes: 2 additions & 0 deletions Configuration/TypoScript/SeoSitemap/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ plugin.tx_seo {
# googleNews = 1

sortField = datetime
# set if you need another sort direction
# sortDirection = DESC
lastModifiedField = tstamp
pid = {$plugin.tx_news.settings.sitemap.startingpoint}
recursive = {$plugin.tx_news.settings.sitemap.recursive}
Expand Down
2 changes: 2 additions & 0 deletions Documentation/Tutorials/BestPractice/Seo/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ The :php:`GeorgRinger\News\Seo\NewsXmlSitemapDataProvider` provides the same fea
- If you are need urls containing day, month or year information
- Setting :typoscript:`excludedTypes` to exclude certain news types from the sitemap
- Setting :typoscript:`googleNews` to load the news differently as required for Google News (newest news first and limit to last two days)
- Setting :typoscript:`sortDirection` to get news sorted to your needs (ASC or DESC)

To enable the category detail page handling, checkout the setting :typoscript:`useCategorySinglePid = 1` in the following full example:

Expand All @@ -149,6 +150,7 @@ To enable the category detail page handling, checkout the setting :typoscript:`u
# googleNews = 1
sortField = datetime
sortDirection = ASC
lastModifiedField = tstamp
pid = 218
recursive = 2
Expand Down

0 comments on commit d2c107e

Please sign in to comment.