List the most popular wordpress posts according to comment count

May 23, 2010

If you want to have a section on the home page where you list the most popular posts of the month, according to comment count. it’s always best to write the code yourself if you can. Once we learn how to query WordPress database, tasks like this become easy. To query WordPress database, we can use the $wpdb->get_results() method. As the parameter, we simply pass a SQL query. In this particular example, let’s say that we only want to display a list of popular posts within our sidebar. We can use the following... [Read the full story]

Display recent posts as thumbnails in sidebar in WordPress 2.9

April 28, 2010

Starting with WordPress 2.9 is no longer need to use custom fields and hacks to have thumbnails in your wordpress articles or even on widgets area, sidebars, footers etc.   For instance, to make a thumbnails area for random latest 10 recent posts, use the following code:   <?php $my_query = new WP_Query('showposts=10&orderby=rand'); if( $my_query->have_posts() ) { echo '<h1>Random Articles</h1>'; while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php $attachments... [Read the full story]

Disable wordpress posts auto saving

August 12, 2009

WordPress have a very useful function that autosaves your posts while you’re typing them in the dashboard. Though, if for some reason you’d like to disable this function, it is very easy to do. To disable WordPress autosaving function, simply open your functions.php file and paste the following code: function disableAutoSave(){ wp_deregister_script('autosave'); } add_action( 'wp_print_scripts', 'disableAutoSave' ); Once you saved the file, WordPress will never autosave a post. To enable autosaving again,... [Read the full story]

Detect if wordpress post has at least one image

July 25, 2009

On a WordPress, it can be really handy to be able to know if a post has at least one image or not, for example for grabbing the first image and display it. To achieve this, simply paste the code below within the loop, on your index.php, search.php or archive.php file. <?php $content = $post->post_content; $searchimages = '~<img [^>]* />~'; /*Run preg_match_all to grab all the images and save the results in $images*/ preg_match_all( $searchimages, $content, $images ); // Check to see if we have at least 1 image $iNumberOfImages... [Read the full story]

Showing the post password form for excerpts in WordPress

June 27, 2009

Many WordPress themes show excerpts on the front page and other archive-type views. When viewing a password-protected post, this message is displayed: There is no excerpt because this is a protected post. While this is fine for many scenarios, it may not be the most helpful piece of text for the average Internet user. Instead of showing the message, we’ll replace it with a password form. Replacing the no excerpt text with a password form WordPress comes packaged with a neat function called get_the_password_form() that... [Read the full story]