Hello,
I was wondering if there was a way to show the inverse of the {date_header}
and {date_footer}
variable pairs? Something like, only show this code if not the first or last entry for the specified date display.
Basically I’m creating a list of entries broken up by year. I’m using the {date_header}
and {date_footer}
variable pairs to add some HTML content to the first and last entries of a year. But I would like to add some content to all the entries that are ONLY not the first and last.
Conditionals using {count}
and {total_results}
don’t really work because they are not affected by any date parameters.
Here’s a basic code example of what I’d like to accomplish where I added a conditional with a fictitious tag {last_yearly_entry}
:
{exp:channel:entries channel="{current_channel}" disable="categories|member_data|pagination"}
{date_heading display="yearly"}
<h2>{entry_date format="%Y"}</h2>
<ul>
<li>
{/date_heading}
<a href="http://{title_permalink={template_group}}">{title}</a>
{if count != "{last_yearly_entry}"}</li><li>{/if}
{date_footer display="yearly"}
</li>
</ul>
{/date_footer}
{/exp:channel:entries}
Have you tried {if count == 1} and {if count == total_results}?
{if count == 1} check if entry is the first entry of your list
{if count == total_results} check if entry is the last entry of your list
{exp:channel:entries channel="{current_channel}" disable="categories|member_data|pagination"}
{if count == 1}
{date_heading display="yearly"}
<h2>{entry_date format="%Y"}</h2>
<ul>
<li>
{/date_heading}
{/if}
<a href="http://{title_permalink={template_group}}">{title}</a>
{if count != "{last_yearly_entry}"}</li><li>{/if}
{if count == total_results}
{date_footer display="yearly"}
</li>
</ul>
{/date_footer}
{/if}
{/exp:channel:entries}
Yep. {if count == 1}
and {if count == total_results}
are my go to’s for creating seamless image grids, but unfortunately they aren’t going to work in this case because I’m breaking my grid up by year.
Here’s the result I’m going for:
<h2>2019</h2>
<ul>
<li>
<a href="#"><img></a>
</li><li>
<a href="#"><img></a>
</li><li>
<a href="#"><img></a>
</li><li>
<a href="#"><img></a>
</li>
</ul>
<h2>2018</h2>
<ul>
<li>
<a href="#"><img></a>
</li><li>
<a href="#"><img></a>
</li><li>
<a href="#"><img></a>
</li><li>
<a href="#"><img></a>
</li>
</ul>
To get that output, could you just do
{exp:channel:entries disable="categories|member_data|pagination"}
{date_heading display="yearly"}
<h2>{entry_date format="%Y"}</h2>
<ul>
{/date_heading}
<li><a href="http://{title_permalink={template_group}}">{title}</a></li>
{date_footer display="yearly"}
</ul>
{/date_footer}
{/exp:channel:entries}
Hi Robin,
Thank you, but unfortunately that’s not what I’m looking for. In order to create a seamless <li>
grid there can’t be a space between the closing and opening <li>
elements within the <ul>
.
Your example is perfectly valid, it just adds an unwanted space between the <li>
’s when using display: inline-block
.
Hence the need to have the output look like this:
<ul>
<li>
<a href="#"><img></a>
</li><li>
<a href="#"><img></a>
</li>
</ul>
Not this:
<ul>
<li><a href="#"><img></a></li>
<li><a href="#"><img></a></li>
</ul>
I was able to come up with a less than elegant solution, but it adds an empty <li>
to the end of each list:
{exp:channel:entries channel="{current_channel}" disable="categories|member_data|pagination"}
{date_heading display="yearly"}
<h2>{entry_date format="%Y"}</h2>
<ul>
<li>
{/date_heading}
<a href="http://{title_permalink={template_group}}">{title}</a>
</li><li>
{date_footer display="yearly"}
</li>
</ul>
{/date_footer}
{/exp:channel:entries}
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.