Grouping articles per year

4 posts by 3 authors in: Forums > CMS Builder
Last Post: December 1, 2014   (RSS)

By Jesus - November 26, 2014

Hi,

Is it possible to group articles per year (based on the published date field)?

I'm building a press release section and I want to group all my articles based on my createdDate field.

Thanks in advance for the advice

By Jesus - November 27, 2014

Hi Dave :) 

Thanks for your answer.

I think having the index page with year links to show articles per page will be the best way to go.

Example...

2014

2015

and then I can have my articles showed on a regular index page (just for the year I want)

Thanks again!

Jesus

By claire - December 1, 2014

Hey there

This is pretty simple - all you need to do is change the where clause on the regular index page to add in the year, if it exists, from the $_REQUEST array.

The year links should look like so:

http://www.yoursite.com/articles.php?year=2014

Then the regular index page will have a getRecords call that looks like this:

if(@$_REQUEST['year'] != "") {
    $where = "year = '".mysql_escape($_REQUEST['year'])."'";
}
else {
    $where = "TRUE";
}

list($articles, $articlesMeta) = getRecords(array(
    'tableName' => 'articles',
    'where' => $where
));

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/