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.

How to code a month/year list of blog posts?

August 30, 2011 6:29pm

Subscribe [5]
  • #1 / Aug 30, 2011 6:29pm

    andy Kirkpatrick

    10 posts

    Hi

    Trying to figure out how to code a conventional list of blog posts from my blog channel, ideally showing number of posts next to the month and year.  Once I can create a list (with all blog links) then I can create a drop down list.  Been searching through the docs but can’t find anything like this.

    Hope someone can help.

    cheers

    andy

    Moved to Community Help forum by Moderator

  • #2 / Aug 30, 2011 6:42pm

    Dave @ Exp:resso

    465 posts

    Well you could look into the month links tag - http://ellislab.com/expressionengine/user-guide/modules/channel/archive_month_links.html or the date heading var -http://ellislab.com/expressionengine/user-guide/modules/channel/variable_pairs.html#var_date_heading or a custom query:

    {exp:query sql="SELECT join_date, COUNT(*) as postcount FROM exp_members GROUP BY FROM_UNIXTIME(join_date,'%d%m%y') ORDER BY join_date"}
    {join_date format="%d %F %Y"} - {postcount}
    
    {/exp:query}

    The above query should do pretty much what you want, but per-day, so you just need to modify the dates to get it to show monthly 😊 Let me know how you get on.

  • #3 / Aug 31, 2011 8:50am

    Sue Crocker

    26054 posts

    Did you want something like this: http://eehowto.com/index.php/howto/archives

    I used:

    {exp:channel:entries channel="howto" orderby="date" sort="desc" limit="100" disable="pagination|custom_fields|categories|member_data"}
    
    {date_heading display="yearly"}
    <h2 class="title">{entry_date format="%Y"}</h2>
    {/date_heading}
    
    {date_heading display="monthly"}
    <h3 class="date">{entry_date format="%F"}</h3>
    {/date_heading}
    
    <ul>
    <li><a href="http://{title_permalink=">{title}</a></li>
    </ul>
    {/exp:channel:entries}

    Will that work for you?

  • #4 / Aug 31, 2011 9:51am

    andy Kirkpatrick

    10 posts

    Thanks for the response.

    This works

    <ul>
    {exp:channel:entries channel="blog" sort="desc" }
        {date_heading display="monthly" }
        <li><a href="#">{entry_date format="%F %Y"}</a></li>
        {/date_heading} 
        <ul>
            <li><a href="http://{url_title_path=blog/view}">{title}</a></li>
        </ul> 
    {/exp:channel:entries}
    </ul>

    but I couldn’t work out how to dislay the number of blogs of each month, and I also need to somehow rap <ul> tags around the list (so a sub list to the month).

    Any ideas?

    Cheers

    andy

  • #5 / Aug 31, 2011 10:02am

    Dave @ Exp:resso

    465 posts

    Maybe SUe can add to this but I don’t think you can display the number of results for each heading (not without PHP at least). Best way to do that would be to use the custom query as above, basically it does a count and a GROUP BY on a specified date interval

  • #6 / Aug 31, 2011 10:26am

    Sue Crocker

    26054 posts

    Hi, andy. This is really more of a How Do I kind of question - other members of the community can assist with helping out if they have any ideas. As Dave mentioned, you’d probably need to do some sort of PHP to get a count.

    Moving to the Community Help forum.

  • #7 / Apr 04, 2012 3:13pm

    Leotta

    2 posts

    Thanks for the response.

    This works

    <ul>
    {exp:channel:entries channel="blog" sort="desc" }
        {date_heading display="monthly" }
        <li><a href="#">{entry_date format="%F %Y"}</a></li>
        {/date_heading} 
        <ul>
            <li><a href="http://{url_title_path=blog/view}">{title}</a></li>
        </ul> 
    {/exp:channel:entries}
    </ul>

     

    Thanks! Exactly what I needed 😊

  • #8 / Apr 05, 2012 10:04am

    glenndavisgroup

    436 posts

    Hi Andy,

    Not sure if this will work but here goes:

    1) Create a new template and call it “count” for example. This template will have the following code in it:

    {exp:query sql="SELECT count(ct.entry_id) as total
      FROM exp_channels c, exp_channel_titles ct 
      where c.channel_name = 'blog' 
        and ct.channel_id = c.channel_id 
        and ct.status = 'open'
        and ct.month = '{embed:month}'
        and ct.year = '{embed:year}'"}
    {total}
    {/exp:query}

    This template will return the total number of entries for the month and year you want. You will need to pass it the month and year so it can correctly return the total entries for the current month and year you are displaying.

    2) Now in your display template change your code to the following:

    <ul>
    {exp:channel:entries channel="blog" sort="desc" }
        {date_heading display="monthly" }
        <li><a href="#">{entry_date format="%F %Y"}</a> ({embed="YourTemplateGroup/count" month="{entry_date format="%m"}" year="{entry_date format="%Y"}"})</li>
        {/date_heading} 
        <ul>
            <li><a href="http://{url_title_path=blog/view}">{title}</a></li>
        </ul> 
    {/exp:channel:entries}
    </ul>

    This will now give you the total number of entries per month next to each month name you display. I hope this helps.


    Mike

  • #9 / May 25, 2012 12:02pm

    Adam Christianson

    115 posts

    Did you want something like this: http://eehowto.com/index.php/howto/archives

    I used:

    {exp:channel:entries channel="howto" orderby="date" sort="desc" limit="100" disable="pagination|custom_fields|categories|member_data"}
    
    {date_heading display="yearly"}
    <h2 class="title">{entry_date format="%Y"}</h2>
    {/date_heading}
    
    {date_heading display="monthly"}
    <h3 class="date">{entry_date format="%F"}</h3>
    {/date_heading}
    
    <ul>
    <li><a href="http://{title_permalink=">{title}</a></li>
    </ul>
    {/exp:channel:entries}

    Will that work for you?

    I have a similar, but slightly different issue. Sue’s solution gets me going in the right direction, but for my particular situation I have two issues. What I want to do is display a single year of archives grouped by month (which is easily done using the channel entries code provided by Sue). Where I have issue is that our database and list of articles is large. I have over 3,000 entries for a given year and when I adjust the ‘limit=’ parameter I get a ‘Fatal error: Allowed memory size of 268435456 bytes exhausted’ message even though I I have 256M allocated. The memory limit could be raised, but the reality is that the channel entries query is just too big with that many records. The other thing is that I really don’t want to display ALL the entries for each month. what I want is to show the first X number of records for each month, say 5, and then provide a link to a separate monthly archive page for that month and year. So the structure I want to achieve is this:

    2012
         - January
              - Article 1
              - Article 2
              - Article 3
              - Article 4
              - Article 5
              - Link to all January 2012 articles…
         - February
              - Article 1
              - Article 2
              - Article 3
              - Article 4
              - Article 5
              - Link to all February 2012 articles…
    etc.

    Currently the way I ended up achieving this was to use the Low Yearly Archives add-on and then from within it’s ‘month’ loop call a nested channel entries tag passing the year, month, as well as limit parameters. This is working, but is also not very efficient (~10-12 seconds and ~290+ queries in an average year. Before caching). Since it’s an archive I can cache the heck out of it, but still. I’m open for more elegant solutions. Any suggestions?

     

  • #10 / May 25, 2012 12:23pm

    Adam Christianson

    115 posts

    I just noticed that a majority of those ~290+ SQL calls are to:

    0.0002    SELECT site_id FROM exp_channels

    Any way to reduce these?

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

ExpressionEngine News!

#eecms, #events, #releases