By darklight on
Hi, I am looking for a way to simply display the number of nodes in a specified content type. Something like this:
print count_nodes('story');
I know this aint valid code, but you get the general idea.
I dont want any frills or specific sorting, I simply wana display a simple number of nodes in a specified content type.
Is this possible?
Thanks in Advance.
Comments
I have so far wrote a small,
I have so far wrote a small, yeh very inefficient code that "works" but is so inneficient I am unwilling to use it on my live site. Surely there's a better way. Here's my current code:
I would be prepared to keep this code, if I only had to run the $count query once, and use the $type variable to specify the node-type for each "print $count" but I cant see any way of doing this. Any ideas?
Beat me to it...
You beat me to it. Following the taxonomy_term_count_nodes model might help. How about this?
(If you're not familiar with static variables, you can read about static variables in the PHP manual.)
Someone else might have a
Someone else might have a better way to do this, but here's the brute force way:
Assuming you want to be able to search for different node types, you'll need a way to specify
$type. For instance, you could wrap this query in a function of its own, and pass the type as an argument:Of course, there's no error checking or anything like that in there. If you want that and don't know how to do it, just ask.
You may also want to check out the taxonomy_term_count_nodes function, though as far as I can tell, it only works for specific terms.
See above
Oops. You beat me to it. See my response to your comment #1 above.
Hey guys, thanks a lot!!!
Hey guys, thanks a lot!!! Grobemo, your code worked wonders!! I did not think of using functions :P thanks a lot guys, I reli appreciate this!