DiggingIntoWordPress

by Chris Coyier & Jeff Starr

Display Total Number of Blogroll Bookmarks

Posted by on

Quick WordPress tip for you today! A reader recently asked about displaying the total number of blogroll bookmarks on their site. This sounds simple enough but not everyone meddles with code these days, so here is a nice PHP snippet that will do the job:

<?php $numlinks = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'");
if (0 < $numlinks) $numlinks = number_format($numlinks); ?>

Place that in your theme file and then customize the output by placing <?php echo $numlinks; ?> wherever you would like to display the results.

A perfect example of this code in use can be seen at this random bookmark site.

3 Responses

  1. have a excellent site. I read all your post and 45 pages . thank you

  2. why don’t you use

    $wpdb->get_var("SELECT * FROM $wpdb->links WHERE link_visible = 'Y'");

Comments are closed. Contact us with any critical information. Thank you!

Code is poetry