English 中文(简体)
Sorting grouped nodes by taxonomy term
原标题:

Ok, here s the problem: I have a list of contacts, which i have created in views, that are grouped by taxonomy terms like so:

(term:) Staff:

(node:)  John Doe
         john@doe.com

(node:)  Jane Doe
         jane@doe.com

(term:) Management:

        Fred Doe
        fred@doe.com

        and so on...

As it is now, i have no idea what decides the order of the taxonomy terms (ie: why is the Staff nodes coming before the Management nodes ).

So what i need to do is to be able to sort the order of the terms, and also the order of the nodes in each category (or what you would call it).

I have tried to sort the terms by weight, but the only thing that happens is that i get duplicated nodes output, and nothing happens with the order of the actual terms.

As for the order of the nodes, i was thinking that maybe a hidden CCK-field with some sort of weight, but i dont know. But the biggest problem is still the order of the categories.

If anyone has an answer to this it would be very helpful.

Thank you.


EDIT:

Strange, i tried that before i asked the question, but now it seems to work. However i still get duplicated nodes when i sort by taxonomy weight, for some reason. I really need to get rid of those. Heres how my view setup look, if its any help:

 
Fields: taxonomy=all terms (limited to one vocabulary) 
image attach content 

Sort criteria: Taxonomy weight:descending

Filters: Taxonomy term id(with depth) // to filter out what page it belongs Node type : contact node published : yes

dont know if that information helps at all

/Anders

最佳回答

The solution is simple, in views you can sort your result by the taxonomy term. You have 3 options as default.

From the views interface:

  • Term Taxonomy terms. Note that using this can cause duplicate nodes to appear in views; you must add filters to reduce the result set.
  • Term ID The taxonomy term ID
  • Taxonomy Weight The term weight field

The sorting in views, is located in the top right corner, and gives a wealth of options as to how you want to sort your results.

Edit:
Duplicates is a known problem with taxonomy terms. The problem is that if a node has two terms that fit it will be included once for each term. When you use the taxonomy term filter, you can reduce duplicates, which should fix your problem:

http://grab.by/16vw

问题回答

I seldom have sort problems with views, but I have to admit it s not something I ever really focused on. Here s a short list of things you might wish to check. If that doesn t solve, it would be great if you could provide some more detail on your settings and what appears to be the default sorting in your current configuration.

  • How did you set the sort criteria in the views UI? You have basic settings available there (top right of the UI panel). See below for some screenshots that should help you finding your way around the configuration.

  • How did you set your taxonomy term order (accessible from somewhere similar to: http://example.com/admin/content/taxonomy/3 - where the number is the taxonomy ID).

  • Here is some more information on sorting capabilities of views.


Screenshots on how to configure sorting

NOTE: In this example I show how to sort nodes according to whether they are published or not, but the procedure applies equally for taxonomy terms.

In this view I already set up some sorting, add yours by clicking on the + button

alt text http://img15.yfrog.com/img15/7118/screenshot005vy.png

Select what kind of content you want to sort

link text http://img3.yfrog.com/img3/2341/screenshot006jkz.png

Select the information you want your content to be sorted by

alt text http://img3.yfrog.com/img3/4816/screenshot007nt.png

And finally select the direction of sorting!

alt text http://img37.yfrog.com/img37/9806/screenshot008ah.png

Now you should be good to go! :) Hope this helps!





相关问题
How do I sort enum members alphabetically in Java?

I have an enum class like the following: public enum Letter { OMEGA_LETTER("Omega"), GAMMA_LETTER("Gamma"), BETA_LETTER("Beta"), ALPHA_LETTER("Alpha"), private final String ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Linq operations against a List of Hashtables?

I m working with a set of legacy DAO code that returns an IList, where each Hashtable represents the row of a dynamically executed SQL query. For example, the List might contain the following records/...

C++ Array Sort Me

Stuck on an array sorter. Have to sort numbers from largest to smallest. I m trying two loops (one nested in the other). Here s the code: int counter=0; // inner counter int counter2=0; // outer ...

Can I Nest OrderBy in .NET?

This doesn t seem to work as I intend. VB.NET: Dim x = Model.Discussions.OrderByDescending(Function(d) d.Messages.OrderByDescending(Function(m) m.Sent).First.Sent) For Each d As Discussion In x ....

sorting elements javascript

I m looking for a way to sort my elements, but it isn t as easy as it sounds. Please let me explain My elements are grouped per 6 elements (thumbnails), each x represents a thumbnail However all ...

热门标签