I just created a small hack to display posts from different category randomly. The advantage is of this widget is that you can show some posts to your visitors which could be hidden in your blog. I have been using this widget for a few days now, so I am not in a position to claim any pros of this widget. I assume that this could help in reducing the bounce rate and the time spent on the site to increase a bit.
I have tested this plugin – I did not find any problem with page loading or any other side effects yet. You feedback could help me in improving this hack. I will release this as a plugin if it works well for me. I am posting the code below so you can use it and let me know your comments
<?php $category_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE taxonomy = 'category'"); ?><?php $r = rand(1,2); ?>
<?php $rcat = rand(1, $category_count); ?>
<?php $kish_cat = get_categories(); ?>
<?php if ($r==1) { ?><?php $catname = $kish_cat[$rcat]->cat_name; ?>
<?php $catid = $kish_cat[$rcat]->cat_ID; ?>
<?php //echo "Catogory name is ".$catname."random category is ".$category_count."-".$rcat; ?><div class="video">
<?php print "<h3>Some Posts From $catname</h3>"; ?><?php $totalen = 85; ?>
<?php $myquery = "showposts=8&cat=".$catid; ?> <?php //print $myquery; ?><?php $recent = new WP_Query($myquery); while($recent->have_posts()) : $recent->the_post();?>
<?php if( get_post_meta($post->ID, "thumbnail", true) ): ?>
<p style="padding:2px; font-size:11px;"><a href="<?php the_permalink() ?>" rel="bookmark"><img style="float:left;margin:2px 10px 0px 0px;width:30px;height:30px;" src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" alt="<?php the_title(); ?>" /></a>
<?php else: ?> <p style="font-size:11px;"><a href="<?php the_permalink() ?>" rel="bookmark"><img style="float:left;margin:2px 10px 0px 0px;width:30px;height:30px;" src="<?php echo $sThumbUrl; ?>" alt="<?php the_title(); ?>" /></a>
<?php endif; ?>
<?php $tit = get_the_title(); ?>
<?php $titlelen = strlen($tit); ?>
<?php $contentlen=$totalen-$titlelen; ?>
<?php $cont = the_content_footer($contentlen); ?>
<a href="<?php the_permalink() ?>"><?php echo $tit; ?></a> - <?php echo $cont." ..</p>"; ?>
<?php //echo $titcont." ..."; ?> <div style="margin-bottom:1px; padding:0px 0px 2px 0px; clear:both;"></div><?php endwhile; ?>
</div>
You can post this code to your blog sidebar. Please change the div class names to your blog name
One more which displays the thumbnails for the latest 20 posts (You can change this number according to your need).
<div class="video"">
<h3>Latest Posts From All Sections</h3>
<?php $recent = new WP_Query("&showposts=20"); while($recent->have_posts()) : $recent->the_post();?> <?php if( get_post_meta($post->ID, "thumbnail", true) ): ?><span><a class="linkopacity" href="<?php the_permalink() ?>" rel="bookmark"><img src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" style = "float:left; margin:0px 10px 10px 0px; width:50px; height:50px;" title = "<?php the_title(); ?>" alt="<?php the_title(); ?>" /></a></span>
<?php else: ?>
<span><a class="linkopacity" href="<?php the_permalink() ?>" rel="bookmark"><img style = "float:left; margin:0px 10px 10px 0px; width:50px; height:50px;" src="<?php echo $sThumbUrl; ?>" alt="<?php the_title(); ?>" /></a></span>
<?php endif; ?>
<?php endwhile; ?>
</div>
The left one is for the random category and the right one is for the Latest 20 posts. I use an hack for automatically updating the thumbnail custom field.
- Delete WordPress Post From Frontend : If you are logged in as...
- Custom Fields in Windows Live Writer : I have been using themes which...
- Display UpComing Posts on your Sidebar – WordPress Blogs : I am sure most of the...
- Gigya – Widget for Bookmarking, Emailing, Posting : Today I have added the Gigya...
- Adding Text Links to below Post for RSS Feeds : Adding sponsored links which is added...
Tweet Samsung Galaxy Note Rom is available for download, but this is only for AT&T users (This ...
Tweet I am currently using a Samsung Galaxy Note and I was using an iPhone 4 and an iPad 2 along wit...