I have a list of stories which I want to group by year, but there doesn't seem to be a fine enough filter in Views to do so; I can only choose the Date field, not a sub-value from there. I see there is a 'Group by Month' module, but it's for 5.x only; is there a way to perform a similar function in Views?

Comments

merlinofchaos’s picture

Status: Active » Fixed

Assuming you're talking about post date or a similar field, go to configure that field. Set "date format" to Custom and set the Custom format to Y

Then set that to your grouping field. You probably also should sort on this field and set the granularity to Year to make sure items appear in the right order.

stopsatgreen’s picture

Got it! Thanks a lot. Quick follow-up: is there any way of declaring the Grouped value? That is, in my News page to have the year appear above the group like so:

2008
- Story
- Story

2007
- Story
- Story

I can't see anything obvious that would allow me to do that.

merlinofchaos’s picture

I don't understand the question; it seems like what you already have should do that? What am I missing?

stopsatgreen’s picture

At the moment the grouping takes place, but I want to know if it's possible to output the grouping criteria as a title; for example, as I'm grouping by year, would it be possible to state the year as a subtitle before each group:

2008
- Story
- Story

2007
- Story
- Story

merlinofchaos’s picture

That should be happening pretty much automatically if you have grouping set up. The list template specifically prints the $title, which is the grouping field.

stopsatgreen’s picture

Hmmm... no, unless I've modded a template and not realised:

http://tinyurl.com/6k2nwf

stopsatgreen’s picture

Status: Fixed » Active

I still can't see a way to put the Group criteria as a title; please see my page for an example of what I mean:

http://217.206.162.200/drupal/?q=latest-news

The news is grouped by year, but I want the year to appear as a title above each group. Is this possible?

merlinofchaos’s picture

In all templates that support grouping, there is a $title variable that is printed. That is the grouping field for that group of templates. This has been verified as functional, so I dunno what it is that's causing this not to work for you.

stopsatgreen’s picture

Status: Active » Fixed

Rather stupidly, I'd overwritten the template in the theme directory and removed the if... print statement which output the title. I did this very early in the build and forgot about it.

Thanks for your patience in helping me track this down.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

idmacdonald’s picture

Status: Closed (fixed) » Active

Hi,

I am reopening this one, because I want to group a list of events by month. I can see the custom display format as an option for a post date, but I am looking to group a list of events by month. I don't see any custom date format options for displaying 'date' module fields.

I supposed it may be a 'date' module issue to allow custom display formats, but if that's not available at the moment, then I guess I need to figure out how to theme the view.

esmerel’s picture

Status: Active » Closed (fixed)

Don't reopen issues that have been closed for nearly a year. Open a new one, and refer to the old one.