5 excellent WordPress Tricks you should have | Mana Blog... for all
Nov 16, 2013

WordPress is a great invention. A lot of people use Wordpress to build their own blog or websites nowadays. Many of these webmasters are even not coder. You may not believe it but that’s the truth. To use Wordpress, you don’t need to master much programming techniques. Wordpress has a comprehensive official guide which is easy to learn. But the official guide is a bit simple and plain that it may not be suitable for people who want to improve their Wordpress skills further. So I collect 5 useful and excellent Wordpress tricks in this article. Hope these could you.

5 excellent WordPress tricks you should have

1. Count article number
For people like me who like writing article on blog, it’s very delighted to see the whole articles number is growing. This trick shows you how to display the article number on your blog or website.
First, you need to add this piece of code in the main function (function.php):
function updateNumbers() {
global $wpdb;
$querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts
WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' ";
$pageposts = $wpdb->get_results($querystr, OBJECT);
$counts = 0 ;
if ($pageposts):
foreach ($pageposts as $post):
setup_postdata($post);
$counts++;
add_post_meta($post->ID, 'incr_number', $counts, true);
update_post_meta($post->ID, 'incr_number', $counts);
endforeach;
endif;
}

add_action ( 'publish_post', 'updateNumbers' );
add_action ( 'deleted_post', 'updateNumbers' );
add_action ( 'edit_post', 'updateNumbers' );

Then add this code to the loop to display article ID:
<?php echo get_post_meta($post->ID,'incr_number',true); ?>

2. Allow contributors to upload files
Many website masters have contributors to post articles. But generally the contributors can’t upload files. They can only edit the text, no image ore video can be added. The plain text may make the article boring. So it’s better to allow contributors to upload some media files. Just add this piece code to the function.php:
if ( current_user_can('contributor') && !current_user_can('upload_files') )
add_action('admin_init', 'allow_contributor_uploads'); function allow_contributor_uploads()
{ $contributor = get_role('contributor'); $contributor->add_cap('upload_files'); }

3. Clear unused short code
You may often add some short code in the article but they are disused for some reason later. The abandoned short code will still remain. If you want to clear them, use this SQL code:
UPDATE wp_post SET post_content = replace(post_content, '[tweet]', '' );

You can run this code with PhpMyAdmin or SQL command line.

4. Make all links open in new window
Even though we can use the html code target=”_blank” to make the link open in new windows. But it’s very inconvenient if you have many links. With this jQuery code you can make all links open in new window and you don’t need to set the target=”_blank” for every link:
jQuery(document).ready(function(){
jQuery("a[rel='external'],a[rel='external nofollow']").click(
function(){window.open(this.href);return false})
});

5. Make Breadcrumb
The Breadcrumb is considered as a very useful and friendly design in web building. The visitors can understand the website structure and know where they locate. Use the tiny code below and you can make a Breadcrumb easily.
<a href="<?php bloginfo(url);?>">Home</a>
<?php if (is_category()) { ;?>
><?php the_category(', ') ?>
<?php }elseif (is_tag()) { ; ?>
><?php single_tag_title(' ') ?>
<?php }elseif (is_single()) { ; ?>
><?php the_category(', ') ?>
<?php }elseif (is_home()) { ; ?>
>Music and Movie
<?php }elseif (is_page()) { ; ?>
><?php the_title() ;?>
<?php } ; ?>


About author
Eddie Hone works for imElfin studio, a professional media software provider which focuses on Blu-ray, DVD, music and online media. He is interested in consumer electronics and web design.

0 comments: