4818 readersIn blogging, it is useful to be able to display your most popular posts. There's WordPress plugins to do that, but you don't need it: This code will display your most popular posts, accordoing to the comments count, without requiring you to use a plugin.Looking for WordPress hosting? Try WP Web Host. Prices starts at
3287 readers
( example screenshot )PHP
function post_word_count() {
$count = 0;
$posts = get_posts( array(
'numberposts' => -1,
'post_type' => array( 'post', 'page' )
));
foreach( $posts as $post )
3586 readersYou might have noticed that the Tuts+ sites have a section on the home page where we list the most popular posts of the month, according to comment count. While there are numerous plugins available, it’s always best to write the code yourself if you can. Too much abstraction is never a good thing! Luckily,
4345 readersNowadays, most websites and web applications are database driven, which means that you, the developer, have to query the database to get the requested information. Let's take a look at a very useful tool to handle SQL queries easily and efficiently on small to medium projects.Like CatsWhoCode? If yes, don't hesitate to check my other
8724 readers
( example screenshot )PHP
add_action("admin_init", "pdf_init");
add_action('save_post', 'save_pdf_link');
function pdf_init(){
add_meta_box("my-pdf", "PDF Document", "pdf_link", "post", "normal", "low");
}
function pdf_link(){
global $post;
$custom = get_post_custom($post->ID);
$link = $custom["link"][0];
$count = 0;
echo '';
$query_pdf_args = array(
'post_type' => 'attachment',
'post_mime_type' =>'application/pdf',
'post_status' => 'inherit',
'posts_per_page' => -1,
);
$query_pdf = new WP_Query( $query_pdf_args );
$pdf = array();
echo '';
echo 'SELECT pdf FILE';
foreach ( $query_pdf->posts as $file) {
3464 readersDid you ever want to display how many blogroll links you have in total? If yes, just read this recipe. It's pretty easy to do using the $wpdb object and some SQL.Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!How to count your blogroll links
3823 readers
( example screenshot )PHP
add_filter('manage_posts_columns', 'posts_columns_attachment_count', 5);
add_action('manage_posts_custom_column', 'posts_custom_columns_attachment_count', 5, 2);
function posts_columns_attachment_count($defaults){
$defaults['wps_post_attachments'] = __('Att');
return $defaults;
}
function posts_custom_columns_attachment_count($column_name, $id){
if($column_name === 'wps_post_attachments'){
$attachments = get_children(array('post_parent'=>$id));
$count = count($attachments);
if($count !=0){echo $count;}
}
}
Visit wpsnipp.com for details on how to setup this WordPress snippet. Share this post. Facebook | StumbleUpon |
4403 readersYou might want to have comments displayed on different spots. For example, displaying the last x comments in a central template. This requires the latest comments or all comments on your site. This is a small solution that scans all the comments, or a certain number, and is supplied with markup. The following code for
20607 readersIf you want to be able to keep a minimum word count for your posts, then just read this recipe. Applying it to your blog can be useful to maintain a clean layout, or ensure your guest writers will not post too short articles on your blog.Looking for WordPress hosting? Try WP Web Host. Prices
3848 readersDo you know that it is possible to insert post in WordPress programmatically? In this recipe, I'll show you how to do it easily.Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!WordPress tip: Insert posts programmatically