表达式引擎 - 帮助处理表达式引擎 ul 内的静态代码

发布于 2024-11-26 20:29:23 字数 1106 浏览 2 评论 0原文

我已设法对最后一个 li 问题进行排序,但现在似乎无法将我的最后一个列表项链接回特定类别中的最新条目。有什么想法吗?

{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've managed to sort the last li issue, but can't seem to now link my last list item back to the latest entry in the specific category. Any ideas?

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

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

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

发布评论

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

评论(1

溇涏 2024-12-03 20:29:23

一个问题是您在 channel:entries 循环之外使用 {count}{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 count == total_results}
    {if count == "5"}
    {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 = 'open' 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}
</ul>{/if}
{/exp:channel:entries}

我还没有测试过这一点,所以让我知道它是否会发脾气。

更新:尝试让“第一个条目”查询起作用:

  • parse="inward" 添加到 exp:query 标记。
  • 尝试直接通过 EE 控制面板中的 SQL 管理器运行 SQL 查询(用category_id 替换 {category_id} 变量),并查看是否返回正确的entry_id。
  • 请记住,此代码假定每个项目在该类别组中仅分配有一个类别。

我上面使用的嵌套 {if} 语句应该可以工作 - 并且使用它比您更新原始帖子时使用的高级语句更好,因为它会导致查询语句每次都要运行。

One issue is that you're using the {count} and {total_results} variables outside of the channel:entries loop, which won't work.

Here's how you can limit the display of the "back" link in this manner, and also link to the first entry in that category (by "first" I assume you mean "newest"):

{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 count == total_results}
    {if count == "5"}
    {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 = 'open' 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}
</ul>{/if}
{/exp:channel:entries}

I haven't tested this, so let me know if it throws a fit.

UPDATE: Things to try to get the "first entry" query to work:

  • Add parse="inward" to the exp:query tag.
  • Try running the SQL query directly via the SQL Manager within the EE control panel (substituting a category_id for the {category_id} variable), and see if that returns the correct entry_id.
  • Remember that this code assumes that each project will only have one category assigned to it in that category group.

The nested {if} statement I used above should work - and it's better to use that than the advanced one you updated your original post with, as it will cause the query statement to run every time.

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