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.

Need some help brainstorming how to divide channel entries by year

April 21, 2012 11:30am

Subscribe [2]
  • #1 / Apr 21, 2012 11:30am

    5BYFIVE Creative

    159 posts

    I have a page on a new site that displays a list of quarterly reports (pdfs). I have a “quarterly reports” channel with a basic “title” and “file upload” field. This worked fine, but now they want the quarterly reports divided up and displayed on the front-end by year. Any thoughts as to how I can divide these up and still only have one channel?

  • #2 / Apr 21, 2012 11:53am

    Bhashkar Yadav

    727 posts

    could you please explain that how you are showing quarterly reports. if you are showing like :

    2011, first quarter report
    2011, second quarter report
    2011, third quarter report
    .....
    .....
    ....

    or you are showing in any other way. also please share your channel entry tag.

  • #3 / Apr 21, 2012 12:46pm

    5BYFIVE Creative

    159 posts

    could you please explain that how you are showing quarterly reports. if you are showing like :

    2011, first quarter report
    2011, second quarter report
    2011, third quarter report
    .....
    .....
    ....

    or you are showing in any other way. also please share your channel entry tag.

    Sure!

    Currently they are listed like this…

    Fourth Quarter 2011 Form 10-Q
    Third Quarter 2011 Form 10-Q
    Second Quarter 2011 Form 10-Q
    First Quarter 2011 Form 10-Q
    Fourth Quarter 2010 Form 10-Q
    Third Quarter 2010 Form 10-Q
    Second Quarter 2010 Form 10-Q
    First Quarter 2010 Form 10-Q


    I need something like this…

    2011(heading)

    Fourth Quarter 2011 Form 10-Q
    Third Quarter 2011 Form 10-Q
    Second Quarter 2011 Form 10-Q
    First Quarter 2011 Form 10-Q

    2010(heading)

    Fourth Quarter 2010 Form 10-Q
    Third Quarter 2010 Form 10-Q
    Second Quarter 2010 Form 10-Q
    First Quarter 2010 Form 10-Q

    ...


    I can’t just manually divide them into years in the template because it needs to be automated so when the client adds year 2012, 2013, etc. forms the new headings need to appear as well.

    {exp:channel:entries channel="reports_quarterly" disable="categories|member_data|category_fields" dynamic="no"}
        <article class="pdf_summary">
        <h1><a href="http://{quarterly_reports_file}">{title}</a></h1>
        {entry_date format="%F %Y"}
        </article> 
       {/exp:channel:entries}

    Thanks for looking into this!

     

  • #4 / Apr 21, 2012 1:32pm

    Bhashkar Yadav

    727 posts

    Hi MikeTheVike,

    I don’t think, you can achieve this with channel entries tags. here you should use a PHP code.

    i can suggest you a simple PHP code(not tested code)

    $this->EE =& get_instance();
     $current_year = date('Y');
     
     for($i = 0; $i < 10; $i++){
      $yr = $current_year - $i;
      $q = $this->EE->db-query("SELECT exp_channel_titles.title AS title, exp_channel_titles.entry_date AS entry_date, exp_channel_data.[field_id_1] AS quarterly_reports_file
            FROM exp_channel_titles 
            INNNER JOIN exp_channel_data ON exp_channel_titles.entry_id=exp_channel_data.entry_id
            WHERE exp_channel_titles.channel_id=[channel_id]
            AND exp_channel_titles.title LIKE '%".$yr."%'");
      echo '<h2>'.$yr.'</h2><p>';<br />
      foreach($q->result_array() as $row){<br />
       $pdf_path = "[Put here pdf directory URL]".preg_replace("^\{(.*?)\}^","" , $row['quarterly_reports_file']);<br />
       echo "<h1><a href="http://.$pdf_path.">".$row['title']."</a></h1>";<br />
       echo "".date($row['entry_date'], '%F %Y')."";<br />
      }<br />
     }

    Please Note : place the [field_id_1], [channel_id] and [Put here pdf directory URL] with appropriate value.

    Hope this would help you.


    Best Regards,

  • #5 / Apr 21, 2012 9:49pm

    John St-Amand

    865 posts

  • #6 / Apr 23, 2012 10:32am

    5BYFIVE Creative

    159 posts

    Why not simply use the date heading tag pair? http://ellislab.com/expressionengine/user-guide/modules/channel/channel_entries.html#variable-pairs

    Bhashkar, thanks for your help, but I usually try and avoid adding PHP to my templates if I can.

    John St-Amand, that looks like it might work! I’ll test it out and see what happens. I think the only thing that might give me problems is that the entry for quarter 4 of a year might not be posted until the next year. Might have to tell the client to set the dates manually. Thanks for your help on this. I noticed you helping people in some other threads as well, glad to see there are still people helping out on the forums here.

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

ExpressionEngine News!

#eecms, #events, #releases