November 2012 Update: This issue was originally filed in 2009 to talk about porting Term Node Count to Drupal 7. After much discussion, no one took the lead, and we are now looking at a Drupal 8 release in less than a year. It would make more sense to develop for Drupal 8, however, a few people are wanting this module to handle counting large numbers of term nodes for current Drupal 7 sites. Although Views can inherently handle counting of a few thousand nodes, the process is too slow in Views for numbers higher than that. If anyone is interested in doing this, perhaps a new issue should be opened, since this one has so many unrelated support questions and old references.
Previous summary:
Someone just pointed me here from #602240: Re-add taxonomy_term_count_nodes(). Just a note that we completely removed taxonomy_term_count_nodes() from Drupal 7, which leaves modules relying on that function a choice between #603236: Add count facility to field_attach_query() or this module. In the interests of D7CX I'm opening this to start discussions about a D7 port.
Comment | File | Size | Author |
---|---|---|---|
#38 | term_node_count.zip | 30.94 KB | shadcn |
Comments
Comment #1
archard CreditAttribution: archard commentedIt shouldn't be hard at all to port this to D7. Don't be surprised if there is a release from day 1.
Comment #2
catchCool. If any taxonomy changes look weird (there's a lot, like 80% of the module), just find me in irc.
Also consider tagging the project with d7cx if you're planning a prompt upgrade: http://cyrve.com/d7cx
Thanks :)
Comment #3
davidzz CreditAttribution: davidzz commentedSubscribing
Comment #4
CSCharabaruk CreditAttribution: CSCharabaruk commentedSubscribing -- D7 final seems pretty close, still looking to hit for launch day?
Comment #5
zorp CreditAttribution: zorp commentedSubscribing
Comment #6
ranavaibhavsubscribing
Comment #7
jodam CreditAttribution: jodam commentedSubscribing
Comment #8
boftx CreditAttribution: boftx commentedsubscribe
Comment #9
jodam CreditAttribution: jodam commentedmy version for Drupal 7, code to module
Comment #10
vitok-dupe CreditAttribution: vitok-dupe commentedsubscribe
Comment #11
a.siebel CreditAttribution: a.siebel commentedsubscribe :-)
Comment #12
picciuto CreditAttribution: picciuto commented@Jodam, where do you put that code? In a block?
Comment #13
Barfly CreditAttribution: Barfly commentedsubscribe
Comment #14
erdembey CreditAttribution: erdembey commentedsubscribe
Comment #15
erdembey CreditAttribution: erdembey commentedRenaming for better tracking ...
Comment #16
yugongtian CreditAttribution: yugongtian commented+1
Comment #17
dotist CreditAttribution: dotist commentedsubscribe
Comment #18
kenorb CreditAttribution: kenorb commentedI'm not sure if there is sense to port this module to Drupal 7.
You could simply achieve this functionality with Views 3.x it-self.
Instruction for Drupal 6 (for Drupal 7, the naming could be different):
1. Create Taxonomy Views.
2. Add relationship to the node (in case if you want to count number of nodes).
3. Enable grouping (Group by)
(or "Use aggregation" toggle in D7, then set the "Aggregation Settings" for each field)
4. In Style Settings/Format set Grouping field to 'Term ID' or 'Node ID' (depends of your query)5. Add new field 'Node: NID' and set Group type to: Count
It depends what do you need. If you need to count nodes or terms.
See: #1132368: How to display item/node count?
The only thing that this module do, it keeping the static numbers of nodes in the table. Those numbers are not always refreshed (I had some differences), site is slowing down (by monitoring changes to terms), you can't count with filters (for specified content type), etc.
With Views we have better flexibility, caching, filtering, sorting available, counting per type, etc.
Comment #19
kenorb CreditAttribution: kenorb commentedComment #20
dotist CreditAttribution: dotist commentedFantastic!
I had a feeling this would be possible w/ Views 3.x w/o any additional modules.
Thanks for the explanation. In my case, i also wanted to filter out all terms w/ zero related content, which is easy once the grouping/relationship is established.
One thing to note, in your number 4, i guess it's no longer called "Styles" but rather "Format".
Thanks,
Isaac
Comment #21
kenorb CreditAttribution: kenorb commentedI just found out, that step 4 is not necessary. It should work as well without setting Grouping field.
I done it, because I'd some problem: #1145514: 'Grouping field' ignoring 'Exclude from display' settings when figuring out this functionality.
Comment #22
OldAccount CreditAttribution: OldAccount commentedHow could this be changed to show a count of items with a certain taxonomy term? Say I have a page "/products/category/sub-category" and I wanted to show how many items have the sub-category term. This seems like it should be simple but I've messed with the Relationships options for hours now and can't get this working. Can you please explain step #2 in more detail, how to add this relationship? Thanks!
Comment #23
kenorb CreditAttribution: kenorb commented@lrobeson:
If you have node based view, you don't have to have relationship (probably). If you have Taxonomy based View, you should add:
'Taxonomy: Node' (Get all nodes tagged with a term.)
Then you have to count how many nodes per term you have which should be: COUNT(nid).
If it doesn't work, please raise separate support ticket for Views, what you trying to achieve.
Comment #24
Jerome F CreditAttribution: Jerome F commentedsubscribe for further reading
Comment #25
kevin-bcr CreditAttribution: kevin-bcr commentedTo those participating in this thread:
I would appreciate it if you could give a little more detail on the process above:
1. Create Taxonomy Views.
2. Add relationship to the node (in case if you want to count number of nodes).
3. Enable grouping (Group by)
4. Add new field 'Node: NID' and set Group type to: Count
I currently have a Taxonomy I've created (Resource Types) and would like page or block views that show them in format, like:
Charts (43)
Maps (34)
Timelines (15) ...
Having created my taxonomy, what do you mean by "Create Taxonomy Views." The only place I can see where adding a relationship comes into play is if I create a Content Type. Anyway, I'm confused by what is meant by the first and second steps in the above process.
Thank you!
Kevin
Comment #26
shadcn CreditAttribution: shadcn commentedCan anyone confirm if #18 works? If it does, I don't think we need to port this module to 7 and I'll add a note to the module page. Thanks
Comment #27
klausiYes, #18 works, thanks kenorb! So I also think a port is not necessary.
Comment #28
Anonymous (not verified) CreditAttribution: Anonymous commentedD7 instructions at #18 are linked to from the project page.
Comment #29
rickumali CreditAttribution: rickumali commentedI appreciated seeing this post, and the steps at #18 indeed work. The piece that was most confusing to me was Step 3 ("Enable grouping"). In Views, this is done by the "Use aggregation" toggle, under the Advanced menu on the main View page. Once you toggle this, you will have the ability to set the "Aggregation Settings" for each field.
Comment #30
Anonymous (not verified) CreditAttribution: Anonymous commentedI think the module's advantage was storing the counts in the database, for each node insert +1 or delete -1. The Views approach is not scalable beyond a few thousand items or so.
Comment #31
klausiViews does caching, so this should not be a problem even for large data sets.
Comment #32
andypost#18 is not clear about a trouble with that in some cases counts are not updated which seems strange.
7.x branch contains usable code that could be used for upgrade path, also I'd like to note that sometimes it's a really useful to have a counter part of term. Suppose the module could introduce different kind of counters: per node-type and cumulative.
Let's roll out 7.x dev version and I think this module could be useful and probably community will help to improve it
Comment #33
Anonymous (not verified) CreditAttribution: Anonymous commented@#31 it does pose a problem! MySQL will crash if you try to count X million nodes. This is irrelevant to Views caching: it never gets cached because the server crashes. Think about MySQL max execution time, etc.
The only stable solution is incremental counting, triggered by node insert/delete. So we still need the old module.
Of course you can happily use Views 3 for small datasets. But it will eventually crash for large datasets or at least slow down your server.
Even better is using MySQL innoDB triggers, but that's another story ;)
Comment #34
xanderol CreditAttribution: xanderol commentedI'm lost at step 3. How do I enable grouping?
Edit: never mind I see the explanation at #29. Missed it the first read through.
Comment #35
iancawthorne CreditAttribution: iancawthorne commentedHello, I'm quite confused by these instructions. I'm using term_node_count to sort a view in Drupal 6. Are these the steps to achieve this in Drupal 7?
Comment #36
shadcn CreditAttribution: shadcn commentedYou can use step above to do same in views 3. or use the Drupal 7 version of this module which comes with an example view exported. But see morningtime's comments on caching for large dataset.
Comment #37
iancawthorne CreditAttribution: iancawthorne commentedWhere is the Drupal 7 version of this module? The project page does not have a module to download. There is information in the description for the module about Drupal 7 which just links to this thread. I can't see a example exported view on this thread?
Comment #38
shadcn CreditAttribution: shadcn commentedMy bad. I thought i added a release some time back ;) here's an export that should be a good starting point to build above in views.
Comment #39
andypostFor D7 seems more promising way to use votingapi + rules to calc any stats the site needs
#38 has schema implementation but no updates are happen to update counters
Comment #40
andyposttaking into account #1007096: Port Views Content Cache to Drupal 7
This is a only module which makes countable part of terms
EDIT: having this project abandoned is bad idea as to make this with views
Comment #41
quardzI succeed with Computed field in Drupal, but needs to save the terms often with bulk operation. Its a dirty way but works for me.
Some Problem : You needs to create a bulk operation view and run to save the terms often, so the latest value will get updated.
Comment #42
andypostAnother issue with views approach - no ability to count a hierarchical taxonomies as original D6 taxonomy_term_count_nodes() does.
Also views fails on large taxonomies so it makes sense to have this modules for D7
Comment #43
alesr CreditAttribution: alesr commentedHow to do it in Drupal 7 on Views 3:
Comment #44
techninja CreditAttribution: techninja commentedNot to beat a dead ticket, but how would the solution in #43 deal with unpublished nodes?
EDIT: Turns out because it uses taxonomy_index, this is somewhat automatic. I'd say that's pretty well managed.
Comment #45
unik CreditAttribution: unik commented#43 worked very good. Thanks alesr
Comment #46
ressa CreditAttribution: ressa commentedNOTE: in #43, "Taxonomy term: Name -> Group results together" is done by setting "Grouping field" to "Taxonomy Term: Name" under "FORMAT: Format: Unformatted list | Settings". Click on "Settings" to do it.
Comment #47
Jframe2002 CreditAttribution: Jframe2002 commentedHi Guys… #18 Worked perfect for me… quick question though… how can i get them to appear inline? any suggestions (i know this might be a stupid question, but I'm new to drupal.
Comment #48
chaiwei CreditAttribution: chaiwei commented#47, not sure if this helps, I am doing in this way
Then it will appear inline.
Comment #49
sachbearbeiter CreditAttribution: sachbearbeiter commentedworked perfectly - thanks a lot ...
Comment #50
giorgio79 CreditAttribution: giorgio79 commented#18 Step 2
Created a taxonomy based view, but in relationships I do not have "node" only these
" Taxonomy: Parent term
The parent term of the term. This can produce duplicate entries if you are using a vocabulary that allows multiple parents.
Taxonomy: Related terms
The related terms of the term. This can produce duplicate entries if there is more than one related term."
Weird.
For the default taxonomy/term this is available
"Taxonomy: Terms on node"
Comment #51
adelka CreditAttribution: adelka commentedI have two vocabularies:
1. cities (terms: new york, chicago....)
2. food (terms: pizza, pasta, kebab....)
I would like to create the block like this:
if I go to /new-york page I will see count number for all of the relevant food, like:
New York:
pizza(200)
pasta(350)
for Chicago:
pizza(100)
pasta(50)
etc.
If no city selected, I would like to have number of all of the foods (this solution is proposed here and works).
Any idea?
Comment #52
kingdee40 CreditAttribution: kingdee40 commentedTerm node count module error when installing:
DatabaseSchemaObjectExistsException: Table term_node_count already exists. in DatabaseSchema->createTable() (line 652 of C:\wamp\www\site\includes\database\schema.inc).
Comment #53
dgoldenbaum CreditAttribution: dgoldenbaum commentedkenorb's #18 post was very helpful... I realized it might be helpful for folks to see the same explanation but with updated terminology for Drupal 7.
1. Add a new view of type: taxonomy
2. Add relationship: Taxonomy term: Content with term
3. Other / Use aggregation = Yes
4. Add new field: Content: NID, in the next pane, set aggregation type to count
Comment #54
Anonymous (not verified) CreditAttribution: Anonymous commentedConfirmed that #43 worked for me on Drupal 7 + Views 3. Thank you! I was pulling my hair out!
I am using this as a block rather than a page and it still worked fine.
Comment #55
MGParisi CreditAttribution: MGParisi commentedThis is currently available with TagClouds http://drupal.org/project/tagclouds
Comment #56
kenorb CreditAttribution: kenorb commentedComment #57
kenorb CreditAttribution: kenorb commentedComment #58
giorgio79 CreditAttribution: giorgio79 commentedUnfortunately Views cannot yet be used as php arrays.
However, in D7 terms can have fields, so I am thinking of adding a node count (integer) field to terms, and writing some code that gets the node count.
Comment #59
ghan CreditAttribution: ghan commented#53 is exactly what I've been looking for -- thanks dgoldenbaum and kenorb!
Comment #60
Yorgg CreditAttribution: Yorgg commentedIsn't it possible to filter terms based on date field?
The field doesn't allow relative dates with aggregation.
I understand I must be having a date relationship.
Comment #61
AndrzejG CreditAttribution: AndrzejG commented#48 doesn't work for me. Rewrited [nid] field is still displayed as a record, not inline. I stripped all HTML tags, no success.
Comment #62
srjosh#43 ftw! Thanks.
Comment #63
ahhao CreditAttribution: ahhao commented#43 simple, clear, easy, and is WORKING!
thank you very much.
one more thing is very important to add on.
Solution for #61 problem: Inline Taxonomy Name and [NID]
You must rearrange the [NID] to top of the [Taxonomy term: Name] in Fields
after this, it should appear in REPLACEMENT PATTERNS if you have install Token module.
Comment #64
AndrzejG CreditAttribution: AndrzejG commentedThanks, ahhao, but my problem seems different.
I have:
strategies (1)
system (6)
technology (5)
and would like to have:
strategies (1), system (6), technology (5),...
Comment #65
Yorgg CreditAttribution: Yorgg commentedAndrzejG, did you manage to find how to do it?
Comment #66
ahhao CreditAttribution: ahhao commentedI didnt try it but this may solved the inline problem.
refer to http://drupal.org/node/777840
after this read this
http://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_lin...
or
can this solve by CSS?
Comment #67
AndrzejG CreditAttribution: AndrzejG commentedstaminna - no, I didn't.
As to coding solutions - sorry I perceive this kind of approach as nonsense, and a straight way to clutter Drupal (it is cluttered enough).
-----
Is it difficult to quip Views with "Inline list", to complement HTML list, Grid, Table etc.? Such list could be useful not only for tags, but also to list Titles, Users, Authors etc.
Comment #68
dawehnerWouldn't it be some html list with a different css or do you want to have comma-seperatered values?
Comment #69
AndrzejG CreditAttribution: AndrzejG commentedI think first option (HTML) would be the best, since it could keep the possibility to display items as links to some content (basically to the listing Page, as tags do).
Comment #70
AndrzejG CreditAttribution: AndrzejG commentedHm, I think the best solution would be similar to the display of multivalue fields, as we can type in the custom separator. In this way we can have various displays, for example Tags, Bloggers, cities of events, and much more.
In order to avoid misunderstanding, a note should be added that this format is only for displaying one or two fields...
Comment #71
fishfang CreditAttribution: fishfang commentedI don't know if I can solve my problem with this solution.
I want to display under each node the terms of that node and - for each term - the count, how often this term is used overall. Somethings like this:
Node 1
Term A (3) Term B(2)
Node 2
Term A (3) Term B (2)
Node 3
Term A (3) Term C (1)
I'm not sure if I can use one of these solutions?
Comment #72
Anonymous (not verified) CreditAttribution: Anonymous commentedTake a look at this solution. It does work.
http://drupal.stackexchange.com/questions/9807/view-module-how-to-displa...
Comment #73
couturier CreditAttribution: couturier commentedShouldn't we be applying any effort on this to 8.x-dev?
Comment #74
dawehnerIt is amazing how much work you do in the queues, especially in the last hours!
This issue is so full of different support questions, old discussion in term node count etc. so if there is something to do
we should create a new one, which a clear summary.
Actually i don't really see what views should do.
Comment #75
couturier CreditAttribution: couturier commentedI agree this issue can be closed. I have been working to find a solution for another problem, dawehner, which is why I am closing these issues cluttering the active queue. Usually I am not in here as much because I am not a programmer, but I am happy for people like you who are. Thanks for all your good work!
Comment #76
andypostIf nobody care to add a countable part for taxonomy term let's live this issue in original issue queue
Comment #77
Anonymous (not verified) CreditAttribution: Anonymous commentedI still prefer a D7 module that actually saves the count in a database table, instead of on-the-fly counting for each page-load. It's much better for performance.
Comment #78
kenorb CreditAttribution: kenorb commented@morningtime: Views are supporting caching, you can choose for how long you want to cache the content, instead of using SQL queries. In the other hand both solutions are using SQL queries and using Views the count is calculated by SQL (which has caching as well), so it should be very fast.
Comment #79
yultyyev CreditAttribution: yultyyev commentedCounting nodes with terms works fine with Drupal 7, but how can I add some enhancements to this?
I need to count nodes with terms (e.g. category) with extra argument (e.g. city). Simple counting works fine, when there is no nodes marked with some term, it's shows zeros in term list (myterm1: 0). But when I added a new contextual filter (another relation: node taxonomy field term, contextual filter: "term=city": show all if empty), it works not pretty much. When the argument is empty - it works like it should, but when I set some argument, empty terms items are hiding from term list. I tried to check sql result, and it really return only terms with > 0 nodes when argument is set, and all terms when argument is empty - I just removed "where term='london'", LEFT JOINs may stay there)
Comment #80
icylace CreditAttribution: icylace commentedWhat about #33? Views caching seems irrelevant in the face of the database crashing before anything can get cached.
Comment #81
couturier CreditAttribution: couturier commentedicylace, are you using Drupal 7? This issue is filed under D6. If you are still having problems, please open a new issue with your details. Also, make sure your hosting plan supports D7 with Views. You will need plenty of php memory and other server resources.
Comment #82
icylace CreditAttribution: icylace commented@couturier So, you're saying that #33 does not apply to Drupal 7 + Views 3? If so, then that's great to hear.
Comment #83
couturier CreditAttribution: couturier commented@icylace If I remember correctly, Views caching in D6 was poor and supposedly improved in D7. There is still work to be done which will further improve Views caching in D8 (Views is in core in D8), but the severity of the problems in #33 should be repeated in more current issues if other people are still experiencing them in D7. #33 was posted in 2011, and most sites have transisted to D7 since then. So yes, I believe that comment referred to D6. Please open a new issue and let us know what you are experiencing. You can link your new issue with a reference here, if you wish.
Comment #84
icylace CreditAttribution: icylace commented@couturier It's good to know that D7 views caching has improved but I believe that #33 brought up an issue that had nothing to do with views caching. To quote #33: "MySQL will crash if you try to count X million nodes. This is irrelevant to Views caching" If I'm not mistaken, Term Node Count avoided this issue therefore a D7 version of it would be very useful. I have not experienced any problems yet since I'm in the process of researching what modules I'd like to use for the site I'm building.
Comment #85
couturier CreditAttribution: couturier commented@icylace if your site is new, then you should be developing in Drupal 7, and Term Node Count is not a module in D7, just a View configuration. Export a View from this reference: http://drupal.org/node/603868#comment-4421144
Comment #86
icylace CreditAttribution: icylace commented@couturier I appreciate your effort to help and I will of course use Drupal 7 but my concern, as mentioned in #33, is with the way MySQL would be used. How does the comment you reference, #18, deal with this?
Comment #87
couturier CreditAttribution: couturier commentedThis is an edited record of emails that @icylace and I exchanged in response to the previous post that may be helpful to someone else looking for a Drupal 7 module to handle counts of data sets larger than a few thousand.
couturier:
icylace:
couturier:
icylace:
Conclusion:
Does anyone else have a need to revive the Term Node Count module for Drupal 7, or do you know of another module that will do the same thing?
Comment #88
Anandyrh CreditAttribution: Anandyrh commentedI am not sure of any other module doing this, I am not a code writer, but I have my D6 site running and large number of taxonomies are being used. Now I am trying to upgrade my site to D7 but all my taxonomy pages were dependent on Term node count module. So now, after reading these above responds, I have decided to wait for this excellent module to be ported to D7.
Comment #89
Bright Web Design CreditAttribution: Bright Web Design commentedDear All,
I have created a how to tutorial for all those who are having trouble creating this taxonomy count using views aggregator. Please checkout the tutorial from here.
http://www.brightwebsitedesign.com/how-to-use-views-aggregator-to-create... if you are having trouble or need any assistance just leave a comment I will get back to you with some tips.
Best Wishes.
Comment #90
Andreyy CreditAttribution: Andreyy commentedThis solution doesn't count parent term nodes.
For example, wrong tree is:
- Drupal (0)
-- Drupal 7.1 (2)
-- Drupal 7.2 (2)
-- Drupal 7.3 (2)
Right tree is:
- Drupal (6)
-- Drupal 7.1 (2)
-- Drupal 7.2 (2)
-- Drupal 7.3 (2)
Does anybody know how to count nodes for the parent term?
Comment #91
JoachimF CreditAttribution: JoachimF commentedI'm building a classified advert area on my site - I want to display terms with the number of nodes associated with each term in a list.
I've set my View up as instructed in https://drupal.org/node/603868#comment-5197322
This works fine but I'd also like to display taxonomy terms where there is no content (0) eg:
Comment #91.0
JoachimF CreditAttribution: JoachimF commentedUpdate
Comment #92
chrisck CreditAttribution: chrisck commentededit: duplicate post
Comment #93
chrisck CreditAttribution: chrisck commentedJoachimF, there are at least 3 sets of instructions on how to do exactly what you want on this page. What I think you are missing is that you need to create a view that shows Taxonomy terms, not Nodes. This is done during the creation of your view.
Comment #94
Summit CreditAttribution: Summit commentedHi, can anyone share a drupal 7 view based on above lyrics?
Thanks a lot in advance! Greetings, Martijn