Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By apt94jesse on
Is there a function that will count nodes of a specific content type?
I'm trying to code a 'stats' block and I'd like to display: Total videos: 12, Total Events: 43, etc.
I don't mind querying for this, if there is no function. I started, but...
$countresult = db_query("SELECT n.type FROM {node} n");
$countobject = db_fetch_array($countresult);
Then what? I'm stumped.
Thanks in advance.
-Jesse
Comments
COUNT(*)
to find the count of nodes of type 'blog':
for example, to show in a page snippet the count of nodes of each type:
---
Work: BioRAFT
gracias
Works like a charm, thanks!
-Jesse
wrestlespace.com
Blank white screen
I got a blank white screen after using this code to get the number of audio files on my site. Any help? I can't login into site anymore
Try this
1) Log on
http://localhost/?q=admin/ (replace localhost with appropriate sitename)
Log on directly to your admin ui and delete the node with errors.
Next time please try code at your local host.
2) Errors
I would try following places:
->$node_audio= node_get_audio();
is the audio really required in here - why not type?
-> $count = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE type = 'audio'", audio));
The last audio, shouln't that be $type?
Just wild quesses....
Can't access any page
I cannot access any page, all I get is a blank white screen.
thanks
White screen = PHP error...
PHP error causes white screen. I would suggest to log on directly to admin ui -> The error node is not rendered.
Unfortunate if the proposial did not work.... I've used it a lot...
Then it's not the one error node that causes the issue. Better dig a bit deeper...
SORTED
Thanks all
I went into phpMyAdmin and set all blocks to status (0)
that worked well, so I could log in then from there I deleted the custom block
Now that code up there shows all nodes with the same count from audio
How do I show just one node type eg "audio"
cheers
no expert but...
The above code works great for me... You have a few anomolies in the code you pasted though.
Your "$count" line should read the following:
You don't need the last "audio" in there, unless you were entering "type='%s'", since that would reference an input string at the end of the query. That's why, in the above example, he sets a $type variable, then uses that as the input string at the end of the query.
This works like a charm for my 4.7.4 install at wrestlespace.com. It's on the homepage if you want to see. Also, make sure that "audio" is the exact content type name, and not something like "content_audio" like CCK creates.
Good luck.
-Jesse
Notice how
Thanks, edited it
Would you mind sharing with me your user snippets. I like the layout on your wrestling site
Great job
Thanks
Thanks, its custom straight from bluemarine. I did a WHOLE lot of hacking the page.tpl.php page, because it was a lot faster than learning some of the advanced theming functions of phptemplate, and a lot more flexible.
What snippets do you want? I don't mind sharing, but I honestly may not have time to break them out and explain them for other sites, as they are mostly hardcode for my domain and setup. But I have no problem sharing and cut/pasting anything. Let me know what you'd like.
Profiles display
I liked the way your profile list is displayed, 1st with just the name and profile picture, then the full profile details
Could you share that please
thanks
How to count subscribed User
How can I show the number of users who are subscribed to my site ?
use PHP/API
---
Work: BioRAFT
Thank you
Thank you
Is it possible to only count
Is it possible to only count nodes for a certain user?
On my profile pages I want to create a box called "My Contributions" and print out how many blogs/images that person has added to the website.
How would I do this?
and will this work with
and will this work with Drupal 5?
Me too!
This would be a great block to have on my site. Anyone know how to do this?
Latte/
Changes For 5.0?
What changes to the above code would be needed for 5.0? When I used it in my 5.o site it printed out:
without node names...
content type names instead of mach-readable type names (D5.5)
That code works great in
That code works great in 5.6, but is there a way only to include certain content types?
it is possible to add an if
it is possible to add an if statement just before the print, such as
But there may be better solutions using some parameters with node_get_types. I couldn't figure out this last one unfortunately.
if anyone is interested,
if anyone is interested, Nancyw helped me with the code for displaying the number of nodes of a certain content type. See her comment here. It works in a block, too. :)
Suscribing
Just suscribing for this, because it´s just what I was looking for!
Thanks!
Rosamunda
Buenos Aires | Argentina
www.ligadelconsorcista.org
stats-block userinfo
Hi,
Would it be possible to make a stats-block like this, in which I see which users ads how many of the nodes? And may be also the last date per user he or she added a node?
I need this, because I pay for a sort of development aid people for adding nodes to a system.I believe in economic development aid, for which they have to do something economical for their money, but off course it costs me more than I benefit from it in this project..:(
Thanks for your reply on this!
Greetings,
Martijn
more counting (attached audio nodes)
I've been working on customizing the audio module to display according to my preferences. I found this statement in the audio_feeds.module that seems to test for whether or not audio files are attached to a node (of course I could be wrong about that!). I'd like to insert it in a block of code for an audio player so that it will show up only if a node has audio files attached. At the moment the player appears on all nodes, whether or not they have files attached. If I insert the below line of code, then the audio player doesn't display at all, so obviously I'm doing something wrong. Any ideas?
Anthony
How could add the total comment count of the site?
I know it´s an easy snippet, but it happen that I don´t know how to do it, and the code that i´ve found out there in the forum jungle ;) is for 4.7 and doesn´t work in 5.x...
Thanks!
Rosamunda
Count notes of content-type made by user
Great code. I haven't tried it out yet, but I was wondering if it was possible to count the nodes of a specific content-type made by a specific user? I'd imagine this would be a great contribution to have beside the "Author Information" block!
yes - I would also love to
yes - I would also love to have that.
Count nodes on 6.x
This function for Drupal 6.x have a few changes...using $type , not $name, avoid problems...
Bye
mauro--
you may need to count only published nodes...
...then add this AND status = 1 into query.
$count = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE type = 'contenttype' AND status = 1", $type)); print($count);
Is there any way to grab the
Is there any way to grab the number of nodes of a certain type that the current user has yet to read? For instance, when a user logs in, there is a link to "news" with a small badge icon over it with the total number of unread posts for the node type "blog". Once they click that link and view any number of posts, the number on the badge declines until eventually reaching 0.
+1 For Current Counts
A Block showing the counts of nodes (by type) that a user has subscribed to, have been updated or had additional comments added to them, since their last login.
This is great info! No need
This is great info! No need for a module but simple a MySQL query! Great! Thanx!
Authentically,
BassPlaya
One query
You can do the same in one database query:
I would love that these codes
I would love that
these codes are not the node types, node names should appear
Could you give the code in the node names, please
thanks
I wanted the content type name too... also only certain...
I wanted the content type name too... also only certain content types to be shown...
So i adjusted the code provided by Pepe and came up with this:
Just need to replace the example content type names to your ones...
Hope it helps others....
Guy
I am always interested in paid work... Contact me through Online Business Builders
node or {node}?
Should not the second and third 'node' be {node} and the second 'node_type' {node_type}? Probably your table names are node and node_type without a prefix. But with prefixed table names the code fails.
BTW: you can enter the query in phpMyAdmin as well (with the prefixed table names).
Great, thanks! Is there also
Great, thanks! Is there also a way to limit this to a taxonomy term?
Count nodes on 7.x
What about for users -
What about for users - specific node counts. Im having an issue showing this through views aggregation for 1 out of 8 content types, dont know why.
for drupal 7 version, how do
for drupal 7 version, how do you specify the node type to count?
also how can we show total comments on the site that have been posted?
.
... very useful thread and nice to see how an old story gets updated ....
btw. I noticed this along the search - but found what I needed here - so I thought I can at least mention it for others - http://drupal.org/project/term_node_count .... counting terms - taxonomy ....
Can someone help me here on
Can someone help me here on Drupal 7?
None of these codes seem to work, im trying to print a small line on the user-profile.tpl.php page
I have a block that prints certain information about the users profile being viewed, i want to print the TOTAL NUBER OF NODES that user has created (of all types), and the NUMBER OF TOTAL COMMENTS posted by others on HIS nodes..
Any ideas?