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

发布于 2024-11-27 20:46:28 字数 3168 浏览 1 评论 0原文

可能的重复:
表达式引擎 - 表达式引擎 ul 中静态代码的帮助< /a>

我在链接到 title_permalink“查看”页面的最新条目时遇到问题。我已在此页面上创建了一个链接,但需要它链接到该特定类别中的最新条目。这是我的代码:

{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

Possible Duplicate:
Expression Engine - Help with static code inside expression engine ul

I am having problems linking to a latest entry from a title_permalink "view" page. I have created a link on this page but need it to link to the latest entry in that specific category. This is my code:

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

I would've thought this would be easy enough but it seems not! My code is the code inside the if total_results conditional.

I've tried everything, basically I have numerous projects, and once the end of projects is reached, there is a button that says "Back to start of projects". I need this to go back to the beginning in a loop so to speak.

EDIT:
This is my code after adding the proposed solution below.

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

Here is the link to the page:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对你而言 2024-12-04 20:46:28

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

OK, the issue with my answer to the previous related question was that when using the related_categories_mode parameter, {categories} isn't available. But I realized that all you need for the query is the group_id for the category group anyway. So, try this:

{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: or, if you're able to pass the main entry's {category_id} via an embed, you can do this:

{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}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文