簡體   English   中英

如何將新聞中的 showPrevNext 限制為類別?

[英]How to limit showPrevNext in news to categories?

在帶有 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
}

我想知道為什么我必須添加類別來覆蓋FlexformSettingsIfEmpty 才能得到下面的結果。 這篇文章更多的是關於如何實現上一個/下一個鏈接(settings.detail.showPrevNext)確實尊重類別定義。

我們的客戶有 3 個新聞類別。 如果我將 go 轉到具有一個類別限制的單個頁面(對於詳細信息和列表頁面),我仍然可以 go “轉發”到完全不同類別中的更新新聞。 然而,列表頁面僅顯示該選定類別的新聞。

<f:if condition="{paginated.prev}">
    <n:link newsItem="{paginated.prev}" settings="{settings}" class="ts-prev">
        {paginated.prev.title}
    </n:link>
</f:if>

從來不是這樣嗎? 我是否必須添加一些 Typoscript 或更改 Fluid? 原始代碼使用此設置變量作為包含類別限制的參數。

好的,我查看了 GeorgRinger\News\ViewHelpers\SimplePrevNextViewHelper 並且當前選擇的類別沒有任何限制。

所以這就是我所做的:

  1. 向 viewhelper 注冊一個新的可選參數categories
  2. categories="{settings.categories}"添加到 Detail.html 中的 simplePrevNext 標記
  3. getNeighbours function 中的主查詢添加“額外位置”
  4. 添加附加內容的內容(我首先在 getNeighbours function 中做了)

額外的地方:

if( is_array($newsOfCategory) && count($newsOfCategory) > 0 ){
    $extraWhere[] = $queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter($newsOfCategory, Connection::PARAM_INT_ARRAY));
}

附加內容 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'];
        }
    }
}

將來可能有人可以使用它,或者將其集成到存儲庫中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM