With wordpress sometimes we might like to output details to a seperate page or even outside of our wordpress folder. The following code is an example of how to grab the details for your comment details.
I recently learned this to use it in my personal dashboard so that I could see new comments without having to go into wordpress.
<?php require('path/to/wordpress/wp-blog-header.php'); $comments_count = wp_count_comments(); echo "Comments for site "; echo "Comments in moderation: " . $comments_count->moderated . " "; echo "Comments approved: " . $comments_count->approved . " "; echo "Comments in Spam: " . $comments_count->spam . " "; echo "Comments in Trash: " . $comments_count->trash . " "; echo "Total Comments: " . $comments_count->total_comments . " "; >?
The above code will produce something like this with your comment details :
Comments in moderation: 0
Comments approved: 3
Comments in Spam: 0
Comments in Trash: 0
Total Comments: 3
The important part really is in require() make sure you have the correct path to your wp-blog-header file.
Leave a Reply
Be the First to Comment!