Examples: http://www.bleakgeek.com/archives/2005/04/08/wordpress-top10view-count-plugin/ Version: 1.5 */ /* ## USAGE ## This plugin uses a table in MySQL. You may either open up phpMyAdmin and insert this SQL or you may do it via command line. Either way, it needs to be there to track the stats. use ; create table mostAccessed ( postnumber int not null, cntaccess int not null, primary key(postnumber), unique id(postnumber) ); ## HTML INSTRUCTIONS ## Open your index.php and find this line: And place this line just above that: no permalinks: 0) { add_count($p);}?> using permalinks: 0) { add_count($id);} ?> Now place this code where you want your top10 posts to show up (outside the wp-loop): ## UPDATE ## Want to see how many times a post has been viewed? Follow the instructions below: Then find this line to your index.php: And add this line right below it (or anywhere around it): ID, $before="(Visited ", $after=" times)"); ?> */ function add_count($p_number) { $result = mysql_query("select postnumber, cntaccess from mostAccessed where postnumber = '$p_number'"); $test = 0; while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $row[1] += 1; @mysql_query("update mostAccessed set cntaccess = '$row[1]' where postnumber = '$row[0]'"); $test = 1; } if ($test == 0) { @mysql_query("insert into mostAccessed(postnumber, cntaccess) values('$p_number', '1')"); } } function show_pop_posts() { global $wpdb, $siteurl, $tableposts; $results = $wpdb->get_results("select postnumber, cntaccess from mostAccessed ORDER BY cntaccess DESC LIMIT 10"); foreach ($results as $result) { $postnumber = $result->postnumber; $post = @$wpdb->get_row("SELECT ID, post_title FROM $tableposts WHERE '$postnumber' = ID"); $post_title = substr($post->post_title, 0, 20); $urlperma = get_permalink($post->ID); // echo "
  • ID."&more=1&c=1\" title=\"$text\">$post_title($result->cntaccess)
  • "; /* Use the line below if you use permalinks in your blog */ echo "
  • $post_title ($result->cntaccess)
  • "; } } function show_post_count($postcountID, $before="(Visited ", $after=" times)") { global $wpdb, $tableposts; $resultscount = $wpdb->get_results("select postnumber, cntaccess from mostAccessed WHERE postnumber = $postcountID"); if (isset($resultscount)) { foreach ($resultscount as $resultcount) { $postcount = $resultcount->cntaccess; echo $before.$postcount.$after; } } } ?>