33

I have 8 articles: Article 1 (Gaming), Article 2 (Local News), Article 3 (World News), Article 4 (World News), Article 5 (Gaming), Article 6, Article 7, Article 8.

In a view I would like to group the articles by: "News," "Gaming," and "Other." Combining the world and local news under one category, and moving anything that doesn't have a category to "Other." I didn't want to create a new vocabulary for just this view. I tried to accomplish this using the group by field, but I can't figure out how I could accomplish this using that method.

15

In your content type, you can create a "list" field called, say, Category, with the categories News, Gaming and Other. You can then categorize the content that should appear in your View using that field.

In your View, under Format, choose "Settings." There should be an option to choose a Grouping Field. Select the "Content: Category" field. Your view should now show up grouped according to News, Gaming and Other.

Was that what you had in mind?

UPDATE The above wasn't quite what you were looking for. No problem.

You say you have articles like Article 1 (Gaming), Article 2 (Local News), Article 3 (World News), Article 4 (World News) etc. Is it right that the word in parentheses is a taxonomy term? If not, the below won't be relevant, but I'll assume for now it is.

If so and you want to 'chunk' these terms into three categories, you could certainly modify the Views query or write your own.

Alternately (which is probably easier) you could change your existing vocabulary into a hierarchical taxonomy with News as the super-category and Local News and World News as the subcategories.

So now your vocabulary looks like:

News

  • Local News
  • World News

Gaming

Other

If your content was already tagged with the existing categories, you shouldn't have to change anything.

You could then create a View that displays the fields you want. Add a filter "Term Name," and enter "News." Then, add an attachment display, and attach it to your current View, overriding the filter and setting it to "Gaming." Finally, add a second attachment and override the Filter, changing it to "Other." This should give you the result you want.

3
  • I agree that your method would work. But for my needs it becomes sloppy. This is a one-off view, something I need to do, but creating a new list field in order to tag the articles only for using it for one view doesn't seem very clean. Thanks a ton for the reply though, still helpful. But if anyone has an idea how to hijack the mysql call or do this moreso in code in order to accomplish this without creating a new arbitrary field, it would be helpful! Thanks!
    – mstef
    Jun 8 '11 at 0:09
  • Thanks! I hadn't thought about doing it using a hierarchical taxonomy, thats definitely a lot cleaner, thanks. Only thing i'm worried about is that we use solr to index the site, I don't want the news, gaming, and other to show up in that index so that might create a new problem to sort out. If anyone has any references for doing this in code, it still be appreciated. But thanks a ton g_thom!
    – mstef
    Jun 8 '11 at 13:09
  • @mstef, glad it was useful. I'm not knowledgeable about solr, having never implemented it before. Theming is more my bag, but good luck with the search side.
    – g_thom
    Jun 9 '11 at 9:08
3

You can use too, Views Distinct. This module allow add relationships or other joins in Views often create "duplicate" results. For example, a node with a field that has multiple values may show up in the View once per value in the multi-value field.

0
2

I bumped into this thread while searching for a group-by solution, either using Views or Display Suite (D7). Somehow I cannot get the group by feature g_thom mentioned in the Format section. Should it be there in D7? is there any Views-dependent submodule that I'm missing out? Also, in Display Suite there is a group by feature, but the only option there that's displayed is one of my custom fields that I created (I don't know why this particular one, not another). Unusable in such a case.

My goal is to have Views form a block of links (linking to custom type nodes), grouped by a taxonomy term (the term should be output but not linked to anything).

PS. respect to g_thom for his elaborate help!

3
  • I'm sorry, I should've placed it as a comment, not an answer. My bad.
    – Artur
    Nov 19 '11 at 14:55
  • did you ever figure this out? seems like there is still no way to do it. (D7)
    – user379468
    Feb 3 '12 at 21:43
  • 2
    I'm going to assume you've figured this out already, but Group By isn't going to just show up under the Format heading; you have to click the Settings link next to the Format item under the Format header.
    – EmmyS
    Jun 11 '12 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.