you are in: codestackercodes [RSS] → tag: wordpress [RSS]

wordpress popular posts Delicious Email

show/hide lines
   1  <ul>
   2  <?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");
   3  foreach ($result as $post) {
   4  setup_postdata($post);
   5  $postid = $post->ID;
   6  $title = $post->post_title;
   7  $commentcount = $post->comment_count;
   8  if ($commentcount != 0) { ?>
   9  <li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>">
  10  <?php echo $title ?></a> {<?php echo $commentcount ?>}</li>
  11  <?php } } ?>
  12  </ul>
created by leozera — 22 August 2009 — get a short url — tags: php wordpress embed

short url in wordpress with tinyurl Delicious Email

paste the function in function.php file and call in you template with:

<?php echo ‘’.getShortUrl(get_permalink($post→ID)).‘“>short url’; ?>

show/hide lines
   1  function getShortUrl($url) {
   2    $tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
   3    return $tinyurl;
   4  }
created by leozera — 26 April 2009 — get a short url — tags: php tinyurl wordpress embed

wordpress functions to count posts Delicious Email

for example: save all functions in ‘your_theme/stats.php’

show/hide lines
   1  // comments_count
   2  function comments_count() { 
   3      global $wpdb; 
   4      $count = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'"; 
   5      echo $wpdb->get_var($count); 
   6  } 
   7  // < ?php comments_count() ?> comments
   8  
   9  // posts_count
  10  function posts_count() { 
  11      global $wpdb; 
  12      $count = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'"; 
  13      echo $wpdb->get_var($count); 
  14  } 
  15  // <?php posts_count() ?></strong> articles
  16  
  17  // retro_count
  18  function retro_count() { 
  19      global $wpdb; 
  20      $count = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_type = 'pingback'"; 
  21      echo $wpdb->get_var($count); 
  22  } 
  23  // < ?php retro_count() ?> pingbacks
created by leozera — 18 November 2008 — get a short url — tags: php wordpress embed