How To Display Total Number Of Comments In WordPress
Adding the following snippet will let you display total number of comments in WordPress.
1 2 3 4 5 6 7 |
<?php $numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'"); if (0 < $numcomms) { $numcomms = number_format($numcomms); echo "There's ".$numcomms." total comments on my blog"; } ?> |
Snippet Source/Credit: PHPMagicBook.com
How To Force Categories Widget To Show Empty Categories In WordPress
The following snippet will let you force categories widget to show empty categories in WordPress.
1 2 3 4 5 6 7 8 9 |
<?php add_filter( 'widget_categories_args', 'mytheme_widget_cat_args' ); function mytheme_widget_cat_args($cat_args) { // the default for "hide_empty" = 1, so $cat_args['hide_empty'] = 0; // we can override any other defaults here too return $cat_args; } ?> |
Snippet Source/Credit: WordPress Codex
How To Have Loop Within The Loop In WordPress
The following snippet will let you have loop within the loop in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php if (have_posts()) : while (have_posts()) : the_post(); // the post loop $temp_query = $wp_query; // store it $args = array( 'paged' => $paged, // paginates 'post_type'=>'post', 'posts_per_page' => 3, 'order' => 'DESC' ); $wp_query = new WP_Query($args); while ($wp_query->have_posts()) : $wp_query->the_post(); // -- your new loop -- // endwhile; if (isset($wp_query)) {$wp_query = $temp_query;} // restore loop endwhile; endif; ?> |
Snippet Source/Credit: WP-Snippets.com
How To Hide Login Errors In WordPress
Adding the following snippet to your theme’s functions.php file will let you hide login errors in WordPress.
1 |
<?php add_filter('login_errors', create_function('$a', "return null;")); ?> |
Snippet Source/Credit: WP-Snippets.com
How To Highlight Author Comments In WordPress
Adding the following snippet will let you highlight author comments in WordPress.
1 2 3 4 |
<?php if (1 == $comment->user_id) echo 'author'; ?> |
Snippet Source/Credit: WP-Snippets.com