[英]How to limit showPrevNext in news to categories?
In the TYPO3 CMS 9.5.18 LTS with tx_news 8.3.0 we use the following extension Typoscript:在带有 tx_news 8.3.0 的 TYPO3 CMS 9.5.18 LTS 中,我们使用以下扩展 Typoscript:
plugin.tx_news.settings{
# what is allowed to overwrite with TS
overrideFlexformSettingsIfEmpty := addToList(categories)
overrideFlexformSettingsIfEmpty := addToList(categoryConjunction)
# ids of categories
categories = 3
# category conjunction mode
categoryConjunction = or
}
I wonder why I have to add categories to overrideFlexformSettingsIfEmpty to get the result below.我想知道为什么我必须添加类别来覆盖FlexformSettingsIfEmpty 才能得到下面的结果。 Never the less this post is more about how to achieve that the prev/next links (settings.detail.showPrevNext) does respect the category definition at all.这篇文章更多的是关于如何实现上一个/下一个链接(settings.detail.showPrevNext)确实尊重类别定义。
Our customer has 3 categories for news.我们的客户有 3 个新闻类别。 If I go to a single page that does has a one category limitation (for the detail and the list page) I still eg can go "forward" to newer news in a total different category.如果我将 go 转到具有一个类别限制的单个页面(对于详细信息和列表页面),我仍然可以 go “转发”到完全不同类别中的更新新闻。 However the list page only shows the news of that one selected category.然而,列表页面仅显示该选定类别的新闻。
<f:if condition="{paginated.prev}">
<n:link newsItem="{paginated.prev}" settings="{settings}" class="ts-prev">
{paginated.prev.title}
</n:link>
</f:if>
Wasn't that never the case?从来不是这样吗? Do I have to add some Typoscript or make a change in Fluid?我是否必须添加一些 Typoscript 或更改 Fluid? The original code uses this settings variable as argument which contains the category limitation.原始代码使用此设置变量作为包含类别限制的参数。
Okay I've had a look into the GeorgRinger\News\ViewHelpers\SimplePrevNextViewHelper and there aren't any limitation for the current chosen categories.好的,我查看了 GeorgRinger\News\ViewHelpers\SimplePrevNextViewHelper 并且当前选择的类别没有任何限制。
So here is what I did:所以这就是我所做的:
categories
to the viewhelper向 viewhelper 注册一个新的可选参数categories
categories="{settings.categories}"
to the simplePrevNext tag in the Detail.html将categories="{settings.categories}"
添加到 Detail.html 中的 simplePrevNext 标记getNeighbours
function为getNeighbours
function 中的主查询添加“额外位置”Extra where:额外的地方:
if( is_array($newsOfCategory) && count($newsOfCategory) > 0 ){
$extraWhere[] = $queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter($newsOfCategory, Connection::PARAM_INT_ARRAY));
}
Content for the additional where:附加内容 where:
if( is_string($categories) && preg_match('/^[0-9]+(,[0-9]+)*$/',$categories) ){
$categories = explode(',', $categories);
$tmpCon = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_category_record_mm');
$tmpQB = $tmpCon->createQueryBuilder();
$rows = $tmpQB
->select('uid_foreign')
->from('sys_category_record_mm')
->where(
$tmpQB->expr()->in('uid_local', $tmpQB->createNamedParameter($categories, Connection::PARAM_INT_ARRAY))
)
->andWhere(
$tmpQB->expr()->like('tablenames', $tmpQB->createNamedParameter('tx_news_domain_model_news'))
)
->execute()->fetchAll();
if( is_array($rows) && count($rows) > 0 ){
foreach($rows as $row){
$newsOfCategory[] = $row['uid_foreign'];
}
}
}
May be someone can use that in the future or the will integrate that to the repository.将来可能有人可以使用它,或者将其集成到存储库中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.