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 Dave - November 27, 2014
Hi Zaba,
It is with a little custom code, do you want articles by year with paging (10 articles per page), or a list of year links to show articles by a specific year? Or just a simple list of articles sorted by year with a header in the list for each year?
Sometimes it's easier to design how you want the page to look and then work in reverse from there.
Let me know, thanks!
interactivetools.com
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/