Mobile Website Redirect Code

<?php
$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
$palmpre = strpos($_SERVER['HTTP_USER_AGENT'],"webOS");
$berry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");

if ($iphone || $android || $palmpre || $ipod || $berry == true) 
{
    echo "<script>window.location='http://m.site.com'</script>";
 }
?>

Note: Works when added to the header.php file in most WordPress themes.
Or
Using a JavaScript code you can redirect your mobile visitors to your mobile site. This JS code can either detect screen size or the user-agent.

<script type="text/javascript">
  <!--
  if (screen.width <= 800) {
    window.location = "http://m.domain.com";
  }
  //-->
</script>

List your most popular Posts

<?php
function listPopularPosts() {
    global $wpdb;
    $strBuidler = '';
     
    $result = $wpdb->get_results("SELECT comment_count, ID, post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");
     
    foreach ($result as $post) {
    setup_postdata($post);
    $postId = $post->ID;
    $title = $post->post_title;
    $commentCount = $post->comment_count;
         
    if ($commentCount != 0) {
        $strBuidler .= '<li>';
        $strBuidler .= '<a href="' . get_permalink($postId) . '" title="' . $title . '">' . $title . '</a> ';
        $strBuidler .= '(' . $commentCount . ')';
        $strBuidler .= '</li>';
    }
    }   
     
    return $strBuidler;
}
?>

Usages:

<h2><?php _e('Popular Posts'); ?></h2>
<ul>
    <?php echo(listPopularPosts()); ?>
</ul>