Expression Engine - Help with static code inside expression engine ul

余生颓废 提交于 2019-12-02 10:16:08

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!