ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Archive formatting & grouping

September 04, 2012 2:50am

Subscribe [2]
  • #1 / Sep 04, 2012 2:50am

    Gizmo

    5 posts

    Good afternoon, all,

    I’m probably not thinking this through properly, but I’ve been staring at this for hours with no end in sight 😉

    For my archive page I have:

    {exp:channel:entries channel="blog"}
    <section class="archive">
    {date_heading display="yearly"}
    <strong>{entry_date format="%Y"}</strong>
    {/date_heading}
    
    {entry_date format="%M %j"}
    <h2><a href="http://{url_title_path=blog/}">{title}</a></h2>
    <p></section><br />
    {/exp:channel:entries}

    Produces something along the lines of:

    2012   Title Title Sep 3
              Title Title Aug 21
    2011   Title Title Sep 15

    or:

    <section class="archive">
       <strong>2012</strong>
       Sep 3
       <h2><a href="http://">Title Title</a></h2>
    <p></section></p>
    
    <p><section class="archive"><br />
       Aug 21<br />
      </p><h2><a href="http://">Title Title</a></h2>
    <p></section></p>
    
    <p><section class="archive"><br />
       <strong>2011</strong><br />
       Sep 15<br />
      </p><h2><a href="http://">Title Title</a></h2>
    <p></section>

    However this is not quite what I need. I would like the <section></section> tags to wrap around all the entries for each year, not around every entry (within a year or not). I.e.

    <section class="archive">
       <strong>2012</strong>
       Sep 3
       <h2><a href="http://">Title Title</a></h2>
    <p>   Aug 21<br />
      </p><h2><a href="http://">Title Title</a></h2>
    <p></section></p>
    
    <p><section class="archive"><br />
       <strong>2011</strong><br />
       Sep 15<br />
      </p><h2><a href="http://">Title Title</a></h2>
    <p></section>

    Any thoughts? Many thanks in advance!!

  • #2 / Sep 04, 2012 8:25pm

    John St-Amand

    865 posts

    Ah, I see what you mean - you’re effectively looking for a loop within each year, but the yearly heading variables in the main entries loop don’t give you quite that ability.

    However, I think you can “cheat” it about by also using the yearly footer tag pair - since you can put what you want inside each of those pairs, you could do something like:

    {exp:channel:entries channel="blog"}
    
    {date_heading display="yearly"}
    <section class="archive">
    <strong>{entry_date format="%Y"}</strong>
    {/date_heading}
    
    {entry_date format="%M %j"}
    <h2><a href="http://{url_title_path=blog/}">{title}</a></h2>
    
    <p>{date_footer display="yearly"}<br />
    </section><br />
    {/date_footer}</p>
    
    <p>{/exp:channel:entries}

    So the opening of the section tag pair inserting within the date heading and the closing of the section tag pair inserting within the date footer.  There’s nothing to say that EE requires a date to actually appear in the date footer for the tag pair to work, so I believe that would do the trick.

    Hope that helps.

  • #3 / Sep 04, 2012 10:07pm

    Gizmo

    5 posts

    Brilliant, thank you John - that works a treat and does exactly what I was looking for!

    Thanks again for your great help!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases