Conditional if a post in tt_news belongs to certain category

岁酱吖の 提交于 2020-01-15 04:50:07

问题


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

回答1:


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/

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

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

[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)

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.



来源:https://stackoverflow.com/questions/10144388/conditional-if-a-post-in-tt-news-belongs-to-certain-category

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!