可能重复:
Expression Engine - Help with static code inside expression engine ul
我在链接到title_permalink“view”页面的最新条目时遇到问题。我在此页面上创建了一个链接,但需要将其链接到该特定类别中的最新条目。这是我的代码:
{exp:channel:entries channel="project" limit="6" category_group="1" stop_before="{embed:stop_before}" related_categories_mode="yes" custom_fields="yes"}
{if count == "1"}<ul id="filmStrip">{/if}
<li>
{exp:imgsizer:size src="{project_image}" height="68px" width="137px"}
<a href="{title_permalink='projects-test/view'}"><img src="{sized}" height="{height}" width="{width}" alt=""/></a>
{/exp:imgsizer:size}
<a href="{title_permalink='projects-test/view'}"><p class="thumbTitle">{title}</p></a>
</li>
{if total_results <= '5' AND total_results == count}
<li>
<a href="{path='projects-test/view'}/{first_entry_id}"><img src="../../../images/backtostart.jpg" height="68px" width="137px" alt=""/></a>
<a href="{path='projects-test/view'}/{first_entry_id}"><p class="thumbTitle">Back to start</p></a>
</li>
{/if}
{if count == total_results}</ul>{/if}
{/exp:channel:entries}
我会认为这很容易,但似乎不是!我的代码是if total_results条件中的代码。
我已经尝试了所有的东西,基本上我有很多项目,一旦项目结束,就会出现一个按钮,上面写着“回到项目开始”。我需要这个循环回到开头可以这么说。
修改: 这是我在下面添加建议的解决方案后的代码。
{exp:channel:entries channel="project" limit="6" category_group="1" stop_before="{embed:stop_before}" related_categories_mode="yes" custom_fields="yes"}
{if count == "1"}<ul id="filmStrip">{/if}
<li>
{exp:imgsizer:size src="{project_image}" height="68px" width="137px"}
<a href="{title_permalink='projects-test/view'}"><img src="{sized}" height="{height}" width="{width}" alt=""/></a>
{/exp:imgsizer:size}
<a href="{title_permalink='projects-test/view'}"><p class="thumbTitle">{title}</p></a>
</li>
{if total_results <= '5' AND total_results == count}
{categories show_group="1" limit="1"}
{exp:query sql="SELECT t.entry_id as first_entry_id FROM exp_channel_titles t LEFT JOIN exp_category_posts c ON t.entry_id = c.entry_id WHERE c.cat_id = {category_id} AND t.status != 'closed' ORDER BY t.entry_date DESC LIMIT 1"}
<li>
<a href="{path='projects-test/view'}/{first_entry_id}"><img src="../../../images/backtostart.jpg" height="68px" width="137px" alt=""/></a>
<a href="{path='projects-test/view'}/{first_entry_id}"><p class="thumbTitle">Back to start</p></a>
</li>
{/exp:query}
{/categories}
{/if}
{if count == total_results}</ul>{/if}
{/exp:channel:entries}
以下是该页面的链接:
答案 0 :(得分:0)
好的,我对previous related question的回答的问题是,当使用 related_categories_mode 参数时,{categories}
不可用。但我意识到,无论如何,查询所需要的只是类别组的group_id
。所以,试试这个:
{if total_results <= '5' AND total_results == count}
{exp:query sql="SELECT t.entry_id as first_entry_id FROM exp_channel_titles t LEFT JOIN exp_category_posts p ON t.entry_id = p.entry_id LEFT JOIN exp_categories c ON c.cat_id = p.cat_id WHERE c.group_id = 1 AND t.status != 'closed' ORDER BY t.entry_date DESC LIMIT 1"}
<li>
<a href="{path='projects-test/view'}/{first_entry_id}"><img src="../../../images/backtostart.jpg" height="68px" width="137px" alt=""/></a>
<a href="{path='projects-test/view'}/{first_entry_id}"><p class="thumbTitle">Back to start</p></a>
</li>
{/exp:query}
{/if}
更新:或者,如果您能够通过嵌入传递主条目{category_id}
,则可以执行以下操作:
{if total_results <= '5' AND total_results == count}
{exp:query sql="SELECT t.entry_id as first_entry_id FROM exp_channel_titles t LEFT JOIN exp_category_posts c ON t.entry_id = c.entry_id WHERE c.cat_id = {embed:category_id} AND t.status != 'closed' ORDER BY t.entry_date DESC LIMIT 1"}
<li>
<a href="{path='projects-test/view'}/{first_entry_id}"><img src="../../../images/backtostart.jpg" height="68px" width="137px" alt=""/></a>
<a href="{path='projects-test/view'}/{first_entry_id}"><p class="thumbTitle">Back to start</p></a>
</li>
{/exp:query}
{/if}