简体   繁体   English

如果tt_news中的帖子属于特定类别,则为条件

[英]Conditional if a post in tt_news belongs to certain category

I made a custom marker for tt_news which shows the first image from the media field, OR the third if it belongs to certain category (lets say category with ID = 2). 我为tt_news创建了一个自定义标记,该标记显示了媒体字段中的第一张图像,如果它属于某个类别,则显示第三张图像(假设ID为2的类别)。 I dont know how to make that conditional. 我不知道该怎么做。 This is what I have so far: 这是我到目前为止的内容:

    10 = IMAGE
    10.file{
        width = 550
        height = 350
        import = uploads/pics/
        import{
            field = image
            listNum = 0

            #If also belongs to the category "Startseite", the listNum should be 2
            listNum.stdWrap.override = TEXT
            listNum.stdWrap.override{
                value = 0
                if{
                    #??????
                }
            }
        }
    }

You need to write custom condition as described in doc in userFunc section (bottom) 您需要按照userFunc部分(底部)中的文档所述编写自定义条件

http://typo3.org/documentation/document-library/core-documentation/doc_core_tsref/4.3.2/view/1/4/ http://typo3.org/documentation/document-library/core-documentation/doc_core_tsref/4.3.2/view/1/4/

News and categories are connected with MM relation so you just to check if MM table contains this pair... 新闻和类别与MM关系有关,因此您只需检查MM表是否包含此对...

typo3conf/localconf.php : typo3conf/localconf.php

function user_newsInCategory($catUid) {
    $ttNewsGet = (t3lib_div::_GP('tx_ttnews'));
    $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
        'uid_foreign',
        'tt_news_cat_mm',
        'uid_foreign = ' . $catUid . ' AND uid_local=' . intval($ttNewsGet['tt_news'])
    );
    return ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) ? true : false;
} 

somwhere in TS after your 10 = IMAGE { ... } block: 您的10 = IMAGE { ... }之后的TS中的某处:

[userFunc = user_newsInCategory(2)]
    10.file.import.listNum = 2
[end]

edit: 编辑:

As you can see in the sample it works only if news is displayed (ie. if param &tx_ttnews[tt_news] exists in URL) 如您在示例中所看到的,它仅在显示新闻时才起作用(即,URL中存在参数&tx_ttnews [tt_news])

To check similar check per each list item you need to use custom marker via hook (as described in tt_news manual ) by using extraItemMarkerProcessor - then you can use similar condition per each $row to display different images. 要检查每需要通过钩使用自定义标记(如所描述的每个列表项目类似的检查tt_news手册中通过使用extraItemMarkerProcessor) -然后就可以使用同样的条件每每$行来显示不同的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM