TYPO3 &tx

编程入门 行业动态 更新时间:2024-10-27 10:27:57
本文介绍了TYPO3 &tx_news 需要 ViewHelper 来显示类别中实体的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

任务:在类别菜单中显示每个类别中的项目数,如

Task: in category menu show count of item in each category, like

类别一 (38) 类别二 (14) 等等……

我已尝试按 $demand 计数,但没有成功

I have try count by $demand but did'nt work

<?php
    namespace HIT\huskytheme\ViewHelpers\News;

    class CountCategoriesViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {

        /**
         * @var \GeorgRinger\News\Domain\Repository\NewsRepository
         * @inject
         */
        protected $newsRepository = null;

        /**
         * 
         * @param string $category
         * @return string
         */
        public function render($category) {

            $demand = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('GeorgRinger\\News\\Domain\\Model\\Dto\\NewsDemand');
            //$demand->setDateField('datetime');

            $demand->setStoragePage(10, true);

            // for example by id = 2
            $demand->setCategories(2);

            $demand->setCategoryConjunction('and');
            $demand->setIncludeSubCategories('1');
            //$demand->setArchiveRestriction($settings['archiveRestriction']);

            $statistics = $this->newsRepository->countByCategories($demand);
            \TYPO3\CMS\Core\Utility\DebugUtility::debug($statistics);

            return $this->newsRepository->countByCategories($demand); 

        }

    }

但是如果调用只得到 0

But get just 0, if call

{namespace s=HIT\huskytheme\ViewHelpers} 
{s:news.countCategories(category: 2)}

推荐答案

实际上我找到了获取类别新闻数量的方法.Thx Georg Ringer 和 取消

Actualy i found way to get number of news in Category. Thx Georg Ringer and undko

我的视图助手

<?php

namespace HIT\huskytheme\ViewHelpers\News;

class CountCategoriesViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {

    /**
     * @var \GeorgRinger\News\Domain\Repository\NewsRepository
     * @inject
     */
    protected $newsRepository = null;


    /**
     * 
     * @param \GeorgRinger\News\Domain\Model\Category $category
     * @return string
     */
    public function render($category) {
        /* @var $demand \GeorgRinger\News\Domain\Model\Dto\NewsDemand */
        $demand = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\GeorgRinger\News\Domain\Model\Dto\NewsDemand::class);

        $demand->setCategories(array($category));
        $demand->setCategoryConjunction('and');
        $demand->setIncludeSubCategories(false);

        return count($this->newsRepository->findDemanded($demand));
    }
}

在我的 tx_news Templates/Category/List.html 中

And in my tx_news Templates/Category/List.html

<!-- load my ViewHelper -->
{namespace s=HIT\huskytheme\ViewHelpers} 

在这里添加计数

...
                            <f:link.page title="{category.item.title}" class="current-item" pageUid="{settings.listPid}"
                                         additionalParams="{tx_news_pi1:{overwriteDemand:{categories: category.item.uid}}}">{category.item.title}
                                <span class="postnum">({s:news.countCategories(category: category.item)})</span>
                            </f:link.page>
...

这篇关于TYPO3 &amp;tx_news 需要 ViewHelper 来显示类别中实体的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 08:55:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1187966.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:amp   tx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!