I want to show on my main page the total number of posts and comments, but I am not sure if those are stored in a table? I mean, comments and entries are stored in each blog's wp_ table, I am not sure if the numbers are saved anywhere else?
Is there an easy way to do this? I'd like to show something like "1000 active users, 2500 entries and 10000 comments".
Posts and comments, not that I believe so. Closest I know of is the blog count and user count.
You probably could code something up though.
I guess I could try...I dont much about coding but I could still try for the hell of it :P
I think I could write a query to count all posts/comments from wp_$blogid and print it out. Would that cause a big strain on the server? I mean, it would have to count it everytime someone loads the page that has the code.
I guess I could have another script via cron updating this every X minutes or so, but that'd be too advanced for me.
I'll see what I can do.
I have a generic script that runs though all of the blogs. I have to release that some time. Been busy.
I give up for now :P Cant even make this work right:
<?
require ('wp-config.php');
$result = $wpdb->query("SELECT count(*) FROM wp_2_comments WHERE comment_ID");
echo "$result";
?>
lunabyte
Member
Posted 19 years ago #
If it's site wide, why wreck havoc making an entire db search when you can instead add a filter/action onto the posting of a comment/post that simply adds +1 to a running total stored in a field in the main options table instead?
Tie one onto the delete function, that does a -1, and it's all good.
Look up 1 value, in 1 table, and call it a day. Running a query across all tables in an install isn't wise. On rare occasion it's necessary, but for something as described it certainly would be a waste of resources.
Well, now that you say that its obvious :P
I think that'd be a better, and a simpler way to do things. Plus, I'd have to edit only 2 files IIRC.
I will try it this weekend.
lunabyte
Member
Posted 19 years ago #
Edit 2 files?
Um, no. That's what the hooks in functions are for.
Thats what I ment I think. I have to edit either post.php or something along that.
lunabyte
Member
Posted 19 years ago #
Um, no you don't.
There is absolutely no reason to even think about editing a core file.
The kind folks who wrote this software didn't put action hooks into darn near every function with an output (and then some) just for their health.
Ah, forgot about plugins.