最新条目链接问题-表达式引擎


Latest entry linking issue - Expression Engine

可能重复:
表达式引擎-帮助在表达式引擎ul 中使用静态代码

我在从title_permink"视图"页面链接到最新条目时遇到问题。我已经在这个页面上创建了一个链接,但需要它来链接到该特定类别中的最新条目。这是我的代码:

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

以下是页面链接:

http://www.mclh.co.uk/index.php/projects-test/view/199

好的,我对上一个相关问题的回答的问题是,当使用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}

UPDATE:或者,如果您能够通过嵌入传递主条目的{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}