Wordpress Tips and Tricks

As per market reports, a constant boom have been outlined in the demand of PSD to WordPress related services in the web development industry. The reason is simple – WordPress has become one of the most powerful content management solution that offer great functionalities. With its latest releases such as WordPress version 3.0.5, the WordPress market has been hit by new WordPress coding tricks and techniques very useful for WordPress developers at the time of post styling. In today’s post of CSSCHOPPER, we would like to present some useful time-saving WordPress Coding techniques and tricks for Post Styling worth paying attention.

Trick 1: You can take the foremost advantage of both the post_class() function and the post ID to provide special styling to the posts individually. To apply style post individually open single.php file and replace the loop with

<?php if (have_posts()) : ?>

<?php while (have_posts()) : the_post(); ?>

<div <?php post_class() ?> id=”post-<?php the_ID(); ?>”>

<h3><a href=”<?php the_permalink() ?>”><?php the_title(); ?></a></h3>

<?php the_content(); ?>


<?php endwhile; else: ?>

<?php _e(‘Sorry, no posts matched your criteria.’); ?>

<?php endif; ?>

Trick 2: Simply paste the below mentioned code after “ the _ content ()” function in the “ single.php file “ to display your related posts with a thumbnails below a particular post


$original_post = $post;

$tags = wp_get_post_tags($post->ID);

if ($tags) {

echo ‘<h2>Related Posts</h2>’;

$first_tag = $tags[0]->term_id;


‘tag__in’ => array($first_tag),

‘post__not_in’ => array($post->ID),




$my_query = new WP_Query($args);

if( $my_query->have_posts() ) {

echo “<ul>”;

while ($my_query->have_posts()) : $my_query->the_post(); ?>

<li><img src=”<?php bloginfo(‘template_directory’); ?>/timthumb/timthumb.php?src=<?php echo get_post_meta($post->ID, “post-img”, true); ?>&h=40&w=40&zc=1″ alt=”” /><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></a></li>

<?php endwhile;

echo “</ul>”;



$post = $original_post;



Trick 3: Simply replace the already existing loop in the ” index.php file ” with the below mentioned easy-to-implement code to display all the latest article or blog post on the homepage.


$postnum = 0;

while (have_posts()) : the_post(); ?>

<?php if ($postnum <= 3){ ?>

<div <?php post_class() ?> id=”post-<?php the_ID(); ?>”>

<div class=”date”><span><?php the_time(‘M j’) ?></span></div>

<h2>(<?php echo $postnum;?>)<a href=”<?php the_permalink() ?>”><?php the_title(); ?></a></h2>

<div class=”post-image” style=”text-align:center;”>

<a href=”<?php the_permalink() ?>”><img src=”<?php bloginfo(‘template_directory’ ); ?>/timthumb.php?src=<?php echo catch_that_image(); ?>&amp;w=500&amp;h=200&amp;zc=1″ alt=”<?php the_title(); ?>” /></a>


<p><?php the_content(‘Read the rest of this entry &raquo;’); ?></p>

<p class=”more”><a href=”#”>Read More</a></p>



<?php } else {

<div <?php post_class( ‘single ‘ . $end ); ?> id=”post-<?php the_ID(); ?>”>

<div class=”post-content”>

<h3><a href=”<?php the_permalink() ?>”>(<?php echo $postnum; ?>)<?php the_title(); ?></a> <?php edit_post_link(‘_’, ”, ”); ?></h3>

<p><?php the_excerpt( ” ); ?></p>

<p class=”more”><a href=”#”>Read More ?</a></p>


</div><!– End post –>

<?php }




Trick 4: Replace the “ the_title() ” function with the following code in the single.php file to overwrite post or page titles without any hassle.

<?php $title = get_post_meta($post->ID, “custom-title”, true);

if ($title != “”) {

echo “<h1>”.$title.”</h1>”;

} else { ?>

<h1><?php the_title(); ?></h1>

<?php } ?>

Trick 5: Paste this code wherever you like to display popular post in the sidebar of the homepage.

<h2>Popular Posts</h2>


<?php $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) {


$postid = $post->ID;

$title = $post->post_title;

$commentcount = $post->comment_count;

if ($commentcount != 0) { ?>

<li><a href=”<?php echo get_permalink($postid); ?>” title=”<?php echo $title ?>”>

<?php echo $title ?></a> {<?php echo $commentcount ?>}</li>

<?php } } ?>


The Conclusion

These useful WordPress coding techniques help WordPress developer to address common set of CMS implementation and customization challenges faced by them in day-to-day work.

you can visit https://www.csschopper.com/ to get more related article and blog stuffs.

Posted By: CSSChopper Team

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Ready to get started? Fill the form now!

Related Posts


Looking for a Web Development Services?

Request a FREE Quote.