Hi,
I ve found how to group by first letter a list of node titles. The trick used is to add twice the node title field, to hide one of them, to shorten it to 1 letter and then to use this field to group the results of the views in the style settings.
However I have still one problem, I have few nodes that start by a number and I don't need a new group for each number. Instead I d like to have a special group for all node which start by a number [0-9]
So I will have :
[0-9]
node 1
node 2...
A
node 3
node 4
B
node 5
node 6
...
In your opinion what is the quicker way and the most "sustainable" way to do that ?
Comments
Comment #1
voross commentedSorry,
I have no solution for the second part, but the first paragraph, (how to set up groups) I found very useful, thanks a lot!
Comment #2
wrd commentedHey, I think I can answer this. This is my first answer! Yay!
This is what I did in Drupal 7, but this should easily translate into Drupal 6:
1) Get the Views PHP module: http://drupal.org/project/views_php
- For Drupal 6, get Views Custom Field, which does pretty much the same thing: http://drupal.org/project/views_customfield
2) Add a new Global: PHP field to your display.
3) Use some simple code like this in your Global: PHP field:
4) Group by that field, replacing the grouping you did with your second Title field.
Comment #3
merlinofchaos commentedAnswers should mark the issue fixed. :)
Comment #4
julma commentedThank you very much,
I can confirm it works well with drupal 6.
I am using exactly this code :
Also useful, to find out what fields are accessible you can use:
One last thing is that I would like to add an Alpha Pager made with anchors above the list.
An example of the final resulat is visible here :
http://www.digital-web.com/titles
Anyone knows a good solution to add this apha-pager made with anchors ?
http://drupal.org/node/649626
Comment #5
julma commentedComment #6
esmerel commentedThe default summary view will make that kind of list
Comment #7
julma commentedSorry but I can't find a summary style that do exactly what is here :
http://www.digital-web.com/titles
Using "argument" with default summary style break the display letter by letter.
So here is a beginning of a solution :
Add the option "Rewrite the output of this field" in the Views settings of the "custom php field" and add this rewrite :
<h2 id="[phpcode]">[phpcode]</h2>Then in the header section of the view, add :
This is not a good generic solution because all letters of the pager are displayed even if there are no titles starting with some of them.
I hope It is possible to find a better solution.
Comment #8
mark trappI ran into this, and while #2 is a pretty interesting way to handle it, if you don't need to rewrite grouping field (for example, if you wanted to group all the numeric rows together under "0-9"), you can do this without a separate module:
There are probably a few other issues that this solution doesn't handle, but it handles the simple use case.
Comment #9
Yuri commented@ #8: Dit you actually test that? When I set it up according to the #8 method, the view will not group by the letter, since each letter is shown as a separate header, apparently views still sees each single character field as separate although it appears as the same character. So thats not working.
Comment #10
mark trappYuri,
Yes, I did: that's why I posted it. Please note the time stamps on posts, though: I posted that 6 months ago. There's a chance something's changed since then that makes the solution unviable for your specific use-case. There are other solutions in other comments that might work better for you instead.
Comment #11
dave_______1 commentedJust tested #8 and it worked perfectly!
So logical.
Don't forget to tick the 'Exclude from display' on the field to stop it showing every letter.
Works on the Taxonomy too.
Now I've just go to get a div round each group so I can float the group...
Cheers for the help Mark
EDIT: Use a HTML list and each grouping is in a UL ready to style :)
Comment #12
puzl commentedRan into the same problem. Make sure the 'link this field to its node' is unchecked. Did the trick for me.
Comment #13
ndf commented#8 Nice and simple
Comment #14
andrewtweber commented#8 You're completely missing the point on grouping the numbers together...
Comment #15
silurius commentedTip for anyone who wants to index nodes under multiple titles. (E.g., "Registering for Classes" and "How to Register for Classes" both pointing to the same node.) Link gives you a CCK field that, if set to "unlimited" can be used to create as many instances as you want. Once you've added the field and edited a few nodes, simply replace the node title field in your view with the Link title, and then group your links by first letter using the steps above.
Another tip: if your index has a large number of links, consider giving your users a means of "parachuting" directly to the link they're after by using an exposed filter. This way they don't have to search the page or scroll up and down, looking for the correct link. In my case, I added a display to my view with an exposed filter that pulls from the link title field, and on my index page (using Insert view) I positioned the exposed filter view display at the top and the full index view display just below it.
This was for D7 but should work for D6 as well.
Comment #16
letrotteur commentedInstead of rewriting the field, I used a custom formatter that took care of the case-sensitive issues, transliteration issues and special caracter issues.
You juste have to make sure you checked option 'Use rendered output to group rows' in the views' format settings
so in hook_field_formatter_view I build my formatter like this:
Comment #17
kienan91 commented#8 this work for me ! Thank you !
Comment #18
inman commented#8 for my task, it helped. Thank!
Comment #19
ressaI created a new post, since the original didn't really belong here.
Comment #20
riddhi.addweb commentedComment #21
xoruna#2 and #4 work fine. However, I would like to know how to gather under label "0 - 9" all nodes begining by a non alphabetical character (like a "+" for example, or punctuation). Any idea?
Or if it is simplier, a way classify those nodes by the first letter they contain (thus ignoring non alphabetical characters at the begining).
Comment #22
ggiakoumidakis commentedI can't make this work on Drupal 8, the simple case, with the first letter grouping... Has anyone?
Comment #23
ggiakoumidakis commentedFinally worked, following the #12 direction, it is not clearly mentioned somewhere else, thanks.
Comment #24
mustanggb commentedComment #26
tiagoz#8 still works in D10, thanks!