Bootstrap Templates Bundle

Thursday, February 28, 2013

Setting default post image for different categories

If no image is attach to the post then rhis code will help us to show different post image for different categories


<?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())) : ?>

<?php the_post_thumbnail('thumbnail'); ?>

<?php else :?>

<img src="<?php bloginfo('template_directory'); ?>/category/<?php $category = get_the_category(); echo $category[0]->cat_name; ?>.jpg" />

<?php endif;?>
</div>



make a folder category by name in your theme directory. then add some image for your every category. such as news.jpg,  uncategorized.jpg etc

Floating Share Bar without Plugin


  • First of all, Login to your WordPress Account, this will take you to the dashboard.
  • Now go to Appearance >> Widgets.
  • Now copy the following code from below [ Make sure you copy the entire code]

<!–TheWordpressBlog SideBar Floating Share Buttons Code Start–>
<style>

#pageshare {position:fixed; bottom:15%; left:10px; float:left; border: 1px solid black; border-radius:5px;-moz-border-radius:5px;-webkit-border-radius:5px;background-color:#eff3fa;padding:0 0 2px

0;z-index:10;}

#pageshare .sbutton {float:left;clear:both;margin:5px 5px 0 5px;}

.fb_share_count_top {width:48px !important;}

.fb_share_count_top, .fb_share_count_inner {-moz-border-radius:3px;-webkit-border-radius:3px;}

.FBConnectButton_Small, .FBConnectButton_RTL_Small {width:49px !important; -moz-border-radius:3px;-webkit-border-radius:3px;}

.FBConnectButton_Small .FBConnectButton_Text {padding:2px 2px 3px !important;-moz-border-radius:3px;-webkit-border-radius:3px;font-size:8px;}

</style>
<div id='pageshare' title="Share This With Your Friends">
<div class='sbutton' id='gb'><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like layout="box_count" show_faces="false" font=""></fb:like></div>
<div class='sbutton' id='rt'><a href="http://twitter.com/share" data-count="vertical" >Tweet</a><script src='http://platform.twitter.com/widgets.js' type="text/javascript"></script></div>
<div class='sbutton' id='gplusone'><script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script><g:plusone size="tall"></g:plusone></div>
<div class='sbutton' id='su'><script src="http://www.stumbleupon.com/hostedbadge.php?s=5"></script></div>
<div class='sbutton' id='digg' style='margin-left:3px;width:48px'><script src='http://widgets.digg.com/buttons.js' type='text/javascript'></script><a></a></div>
<br/><div style="clear: both;font-size: 9px;text-align:center;"><a href="http://thewordpressblog.org/how-to-add-floating-share-bar-to-wordpress-without-plugin" target="blank"><font color="black">[Share Bar]<font></font></font></a></div></div>

<!– TheWordpressBlog SideBar Floating Share Buttons Code End–>

http://thewordpressblog.org/how-to-add-floating-share-bar-to-wordpress-without-plugin/

alternate-single-post-template-for-specific-categories


Paste this below code into single.php file and create post-single.php and post-custom.php

<?php
        if ( have_posts() ) { the_post(); rewind_posts(); }
        if ( in_category(1) || in_category(2) || in_category (3) ) {
            include(TEMPLATEPATH . '/post-single.php');
        }
        else {
            include(TEMPLATEPATH . '/post-custom.php');
        }
    ?>


or



<?php
  $post = $wp_query->post;
  if (in_category('portfolio')) {
      include(TEMPLATEPATH.'/single_portfolio.php');
  } elseif (in_category('news')) {
      include(TEMPLATEPATH.'/single_news.php');
  } elseif(in_category('wordpress')) {
      include(TEMPLATEPATH.'/single_wordpress.php');
  }
  else{
      include(TEMPLATEPATH.'/single_default.php');
  }
?>

PHP code for getting thumbnail and default post image

This code will help us to set default thumbnail and getting thumnail


   <div style="margin: 12px;">
         
         <?php if( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail(array(350,250), array ('class' => 'alignleft')); ?>

<?php else : ?>
<img src="<?php echo get_bloginfo('template_directory');?>/images/defaultthumb.png" alt="Default Icon" title="Default Thumb" class="alignright" height="300px" width="460px"/>
<?php endif; ?>
         
       </div>

Display Post Thumbnail Also In Edit Post and Page Overview in admin panel

For this here I'll tell you two Technics. One by Plugins and second by adding some code in Functions.php file .


Technic 1: Simply Download this plugins and activate

You can download from here:  click here to download

Technic2:  Paste this below code into functions.php file 



if ( !function_exists('fb_AddThumbColumn') && function_exists('add_theme_support') ) {
 
 // for post and page
 add_theme_support('post-thumbnails', array( 'post', 'page' ) );
 
 function fb_AddThumbColumn($cols) {
  
  $cols['thumbnail'] = __('Thumbnail');
  
  return $cols;
 }
 
 function fb_AddThumbValue($column_name, $post_id) {
   
   $width = (int) 35;
   $height = (int) 35;
   
   if ( 'thumbnail' == $column_name ) {
    // thumbnail of WP 2.9
    $thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true );
    // image from gallery
    $attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') );
    if ($thumbnail_id)
     $thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
    elseif ($attachments) {
     foreach ( $attachments as $attachment_id => $attachment ) {
      $thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true );
     }
    }
     if ( isset($thumb) && $thumb ) {
      echo $thumb;
     } else {
      echo __('None');
     }
   }
 }
 
 // for posts
 add_filter( 'manage_posts_columns', 'fb_AddThumbColumn' );
 add_action( 'manage_posts_custom_column', 'fb_AddThumbValue', 10, 2 );
 
 // for pages
 add_filter( 'manage_pages_columns', 'fb_AddThumbColumn' );
 add_action( 'manage_pages_custom_column', 'fb_AddThumbValue', 10, 2 );
}

Thursday, February 14, 2013

Setting post image automatically as featured image for post thumbnail

Before using this code I use different types of plugins for showing post thumbnail. But this below code helps me to set my post image automatically as my thumbnail/ featured image, not only that , this code also set a default thumbnail
paste this code into functions.php file


// Get URL of first image in a post
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];

// no image found display default image instead
if(empty($first_img)){
$first_img = "http://newsprotidin.com/wp-content/uploads/2013/02/thumb-150x150.jpg";
}

 $first_img = vt_resize( $first_img, '', 460, 250, true );


return $first_img;
}

Wokiee React eCommerce Template