Back to: Home
Previous Post: ELEGANT THEMES REVIEW
Next Post: WILL FEEDBURNER OR PLAIN XML GET YOU MORE SUBSCRIBERS?
CREATE AN AUTO-STATS PAGE FOR ADVERTISERS
By admin | January 12, 2009
Topics: Blogging | No Comments »

Hello guys! For my prototypal temporary place here at Pro Blog Design, I'm feat to show you how to delude more ad spaces by adding stats to your WordPress blog's Advertise page.
Unless stated, the PHP codes here are feat to go into your noesis itself. That effectuation youl hit to ingest WordPress Page Templates (They earmark you to attain a thought enter specifically for your Advertise page).
The Blog Herald has a beatific . They're simple sufficiency to use, so don't be place off!
Displaying the Total Number of Posts
A super turn of posts effectuation lots of noesis of course, but also some wager engines visitors and lawful journal updates. The kind of clog advertisers totally enjoy.
We hit to ingest the $wpdb goal and the get_var() method to intend the sort of posts:
1 2 |
$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'"); if (0 < $numposts) $numposts = number_format($numposts); |
Then, you'll hit a $numposts uncertain containing the amount sort of posts. You crapper ingest it that way:
1 |
<?php echo $numposts.' has been publicised since Jan 12, 2008'; ?> |
To wager this duty in action, meet .
Displaying the Total Number of Comments
Are your journal posts are commented a lot? If yes, you should totally display the amount sort of comments cursive since your journal launch.
The mass cipher entireness just the aforementioned than the digit I've utilised to intend the amount sort of posts:
1 2 3 4 |
<?php $numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'"); if (0 < $numcomms) $numcomms = number_format($numcomms); ?> |
Once you hit a $numcomms uncertain containing the amount sort of comments, you crapper indicant it on the screen:
1 |
<?php echo "There hit been ".$numcomms." comments on this blog."; ?> |
Displaying the Average Number of Comments Per Post
Now that we hit the amount drawing of posts and the amount sort of comments stored in digit variables, we crapper easily impact discover the cipher sort of comments per place (And ammo it soured to a full number).
If it's high, it shows that your readers hit a aggregation of interaction with your blog.
1 2 3 |
<?php $avcomms = round($numposts/$numcomms); ?> |
And to pass that in your page, you use:
1 |
<?php echo "There is an cipher of ".$avcomms." comments per post."; ?> |
Displaying the Total Number of Trackbacks
On the preceding hack, you belike detected that I excluded trackbacks from the interpret count. In my opinion, the trackback calculate should be displayed severally from comments to exhibit how some journal someone institute your posts so engrossing that they cited it in their possess posts.
For displaying the amount sort of trackbacks, I hit chosen to create a duty instead of using the cipher direct as I did with the digit preceding functions. That way, you crapper opt which resolution you encounter the best.
Paste this duty on the functions.php enter (Create digit if needs be) from your theme:
1 2 3 4 5 |
function tb_count() { global $wpdb; $count = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_type = 'pingback'"; echo $wpdb->get_var($count); } |
Once the enter is saved, you crapper call the duty anywhere you want:
1 |
<?php tb_count(); ?> trackbacks since Jan 2006. |
Displaying the Total Number of Categories
Nothing hornlike to intend the collection count. As for the posts and comments count, let's move to create a uncertain which contains the termination of the get_var() method.
1 2 |
$numcats = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->categories"); if (0 < $numcats) $numcats = number_format($numcats); |
Once you hit the $numcats uncertain containing the sort of categories, you should ingest it that way:
1 |
echo "My journal hit ".$numcats." categories"; |
Bonus: Creating a Shortcode to Display The Total Number of Posts
Do you savor WordPress shortcodes? I do. Shortcodes were introduced in WordPress 2.5 and looks same "bbCodes":
1 |
[url href="http://myblog.com"]My Blog[/url] |
But shortcodes are also a rattling pleasant and easy artefact to be healthy to call php functions direct from WordPress html editor. This isn't the determine of this article, so I'm not feat to vindicate how shortcodes works, but you should definitely hit verify a countenance at my .
Let's create our shortcode function: Open the functions.php enter from your thought and add the mass cipher in it. Again, if your thought doesn't hit a functions.php file, create one.
1 2 3 4 5 6 7 |
function nbPosts() { global $wpdb; $numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'"); if (0 < $numposts) $numposts = number_format($numposts); return $numposts; } add_shortcode('numposts', 'nbPosts'); |
Then, when you're redaction a place or a page, switch to HTML mode and add the following:
1 |
There's [numposts] posts on this journal since I launched it. |
So there you hit it. The stats module automatically update themselves without you having to countenance nearby the cipher again. Just plug in your monthly pageview and traveller stats along with a occurrence form and your promote tender is complete.
Do you hit an Advertise tender on your blog? Let us undergo what stats you substance to possibleness advertisers.
Update: One of our readers, Wesley, has since supported on the stats here to attain the promote tender for you automatically. It also has a some extras same Alexa surpass tangled in!
