I have created a content type of newsletter. The newsletter field has a publish date and I am sorting by the publishing date. With that said, I want to group by year.

I know I can rewrite output but it seems that I can really only use token and then surround those tokens with HTML. I want to do what would seem simple and get the year value from the date and then group by it. It doesn't seem like I should have to manually a year field so that I can group by it. This is very easy in pure SQL.

Do I need to figure out how to theme that and hope that views will group based off of my themed value that would in theory suck out the year from the date field.

Help!!!

Comments

khanz’s picture

i guess views has a default view called archive, which displays monthly archive and you can easily modify it to show yearly listings.

------------
Volvo, Video, Velcro. (I came, I saw, I stuck around.)

scotthoff’s picture

This looks very promising for multiple reasons. I will check it out. I'm creating a clone rather than modifying it so that I have it around for future reference.

scotthoff’s picture

OK. Here is the deal, it does not seem that I can change it. If you look at the SQL,

SELECT DATE_FORMAT((FROM_UNIXTIME(node.created) + INTERVAL -21600 SECOND), '%Y%m') AS created_year_month,
   COUNT(node.nid) AS num_records
 FROM node node 
 WHERE (node.status <> 0) AND (node.type in ('newsletters'))
 GROUP BY created_year_month
  ORDER BY created_year_month DESC 

You can see that it is doing group by and count. I don't think this is standard views functionality? In any case, I could maybe make this work by modifying the actual SQL but this isn't how views works right? You use the GUI and it generates the view for you.

I need to change node.created to a different field created by CCK.

I will update with any success or meaningful failure.

scotthoff’s picture

The system says

The style selected does not utilize fields.

I guess, I thus have NO IDEA where to proceed. How is a view working without fields? If it is using a summarized value, woudn't it indicate the summarized value as a field?

khanz’s picture

you can change the the style from views gui. In the Basic settings there are two options "Style" and "Row style", you can fiddle with it to get desired results.

Edit: you might also want to look at views arguments.

------------
Volvo, Video, Velcro. (I came, I saw, I stuck around.)

scotthoff’s picture

I checked in view arguments before and had very strange results. Maybe I can put up a screenshot to explain.

peacog’s picture

Hi Scott

I need to do something similar i.e. group by Month using a CCK date field instead of the node creation date. Did you find a solution?

scotthoff’s picture

In the end I created an iteration of a view for each year. Not perfect but this allowed me to reach my deadline.

One view filtered for year 1, year 2 , year 3...