Latest entry linking issue - Expression Engine [duplicate]
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_re开发者_JAVA百科sults == 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
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}
精彩评论