2012-03-28 41 views
0

我使用ExpressionEngine 2.2.1並試圖根據類別顯示我的頁面的一部分。如果沒有條目選擇某個類別,我想隱藏整個部分。例如,我有一個網站列出了一個最終會有競爭對手的事件的信息。我希望網頁在競爭對手被選中之前就存在,然後想要在競選者被選中後加入競爭對手。該部分將會有一個表示「競爭對手」的標題。如果沒有競爭對手被分配到這個類別,我不僅不希望它爲競爭對手展示空間,而且我還想隱藏標題。我如何根據類別創建條件?在此基礎上我的研究我當前的代碼適用部分(http://expressionengine.com/archived_forums/viewthread/136676/#759900)不工作:ExpressionEngine如果沒有分類結果,則不會顯示

{if 「{categories show_group=「4」}{category_name}{/categories}」 != 「」} 
    {categories}  
     <h2>COMPETITORS</h2> 
     {exp:channel:entries channel="competitor_profiles_en" category_url_title="london_2d_en" orderby="date" limit="8" } 
     <div class="xx">{competitor_image}</div> 
     {/exp:channel:entries} 
    {/categories} 
{if:else} 
show nothing 
{/if} 

回答

0

這是完整的代碼?

{categories} {/ categories}循環對只能在channel:entries標記對中使用。

我沒有完全跟隨你正在嘗試做的,但有一個條件,你可以在通道內使用:項循環,如果有基於使用的標籤沒有結果:

{if_no_results}

可能這可以用於在模板以類別模式加載時創建所需的視圖,但沒有分配給該類別的條目。

1

難道你不能這樣做嗎?

{exp:channel:entries channel="competitor_profiles_en" category_url_title="london_2d_en" orderby="date" limit="8"} 
    {if count == "1"}<h2>COMPETITORS</h2>{/if} 
    <div class="xx">{competitor_image}</div> 
{/exp:channel:entries} 

或者,如果你這樣做,同時通過所有類別循環:

{exp:channel:categories channel="competitor_profiles_en" show_empty="no"} 

    <h1>{category_name}</h1> 
    {category_description} 

    <h2>COMPETITORS</h2> 
    {exp:channel:entries channel="competitor_profiles_en" category="{category_id}" orderby="date" limit="8"} 
     <div class="xx">{competitor_image}</div> 
    {/exp:channel:entries} 

{/exp:channel:categories} 

請注意,如果你有很多類別,這種嵌套的標籤可能導致相當大的性能損失。

1

我加入parse="inward"channel:entries標籤得到了這個工作:

{exp:channel:entries channel="news" parse="inward"} 

然後if語句如下:

{if '{categories show="135"}{category_name}{/categories}' != ""} 

顯然替換你上面的渠道和類別ID。所以完整的代碼:

{exp:channel:entries channel="news" parse="inward"} 
    {if '{categories show="135"}{category_name}{/categories}' != ""} 
     {!-- do something here --} 
    {/if} 
{/exp:channel:entries}