{if taxonomy != "" OR related_pages != "" OR related_posts != "" OR related_news != ""}
<footer role="contentinfo">
{if taxonomy != ""}
<div id="taxonomy" itemprop="taxonomy">
<h3>Category tags for this page</h3>
<ul property="dcterms:type">
{exp:tagger:tags entry_id="{entry_id}" orderby=”tag_name”}
<li>
<a href="/page/tag/{tagger:urlsafe_tagname}" rel="tag">{tagger:tag_name}</a>
</li>
{/exp:tagger:tags}
</ul>
</div>
{/if}
{if related_pages != ""}
<div id="related-pages">
{related_entries id="related_pages"}
<h3>{title}</h3>
{body}
{/related_entries}
</div>
{/if}
{if related_posts != ""}
<div id="related-posts">
{related_entries id="related_posts"}
<h3>{title}</h3>
{body}
{/related_entries}
</div>
{/if}
{if related_news != ""}
<div id="related-news">
{related_entries id="related_news"}
<h3>{title}</h3>
{body}
{/related_entries}
</div>
{/if}
</footer>
{/if}
所以,我正在寻找条件代码,如果任何分类法,related_pages,related_posts或related_news都不为空,首先只显示一个页脚元素。请注意,related_ *是所有关系字段ID。
在此if语句中是嵌套的条件语句,如果相应的ID不为空,则只显示内容块。不幸的是,即使没有选择相关内容,EE似乎也看不到关系字段是空的。
有没有人知道在没有选择内容时关系字段ID解析了什么,或者有其他解决方法来处理我在此代码中尝试做的事情?
答案 0 :(得分:1)
有点啰嗦,但是......
{if "{taxonomy}" != "" OR
"{related_entries id="related_pages"}{entry_id}{/related_entries}" != "" OR
"{related_entries id="related_posts"}{entry_id}{/related_entries}" != "" OR
"{related_entries id="related_news"}{entry_id}{/related_entries}" != ""}
...
{if "{related_entries id="related_pages"}{entry_id}{/related_entries}" != ""}
...
{if "{related_entries id="related_posts"}{entry_id}{/related_entries}" != ""}
...
{if "{related_entries id="related_news"}{entry_id}{/related_entries}" != ""}
...
如果你的预算可以延伸到它,那么Playa附加组件就是关系之王,让人际关系变得轻而易举。
答案 1 :(得分:0)
感谢彼得·刘易斯(Peter Lewis)让我走上了正确的道路。请注意,当您在ID周围使用双引号时,您似乎必须在每个引用周围添加它们,否则抛出异常。此外,limit attribute or count isn't available on related_entries但可以使用自定义PHP计数进行处理,如链接的论坛帖子中所示。
以下是适用的模板代码:
{if "{taxonomy}" != "" OR
"{related_entries id="related_pages"}{entry_id}{/related_entries}" != "" OR
"{related_entries id="related_posts"}{entry_id}{/related_entries}" != "" OR
"{related_entries id="related_news"}{entry_id}{/related_entries}" != ""}
...
{if taxonomy != ""}
...
{if "{related_entries id="related_pages"}{entry_id}{/related_entries}" != ""}
...
{if "{related_entries id="related_posts"}{entry_id}{/related_entries}" != ""}
...
{if "{related_entries id="related_news"}{entry_id}{/related_entries}" != ""}
...