如果 tt_news 中的帖子属于某个类别,则有条件 [英] Conditional if a post in tt_news belongs to certain category

查看:24
本文介绍了如果 tt_news 中的帖子属于某个类别,则有条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 tt_news 制作了一个自定义标记,它显示了媒体字段中的第一张图片,或者如果它属于某个类别(比如说 ID = 2 的类别),则显示第三张图片.我不知道如何设置条件.这是我目前所拥有的:

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). 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{
                    #??????
                }
            }
        }
    }

推荐答案

您需要按照 userFunc 部分(底部)中的文档所述编写自定义条件

You need to write custom condition as described in doc in userFunc section (bottom)

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

新闻和类别是用MM关系连接的,所以你只需检查MM表是否包含这对......

News and categories are connected with MM relation so you just to check if MM table contains this pair...

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;
} 

在 TS 之后你的 10 = IMAGE { ... } 块:

somwhere in TS after your 10 = IMAGE { ... } block:

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

如您在示例中所见,它仅在显示新闻时才起作用(即,如果 URL 中存在参数 &tx_ttnews[tt_news])

As you can see in the sample it works only if news is displayed (ie. if param &tx_ttnews[tt_news] exists in URL)

要检查每个列表项的类似检查,您需要通过钩子使用自定义标记(如在 tt_news 手册中)通过使用 extraItemMarkerProcessor - 然后您可以在每个 $row 中使用类似的条件来显示不同的图像.

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 中的帖子属于某个类别,则有条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆