Breadcrumb for post

function the_breadcrumb() {
		echo '<ul id="crumbs">';
	if (!is_home()) {
		echo '<li><a href="';
		echo home_url();
		echo '">';
		echo 'Home';
		echo "</a></li>";
		if (is_category() || is_single()) {
			echo '<li>';
			echo the_category();
			echo '</li>';
		} 
		elseif (is_search()) {
			echo '<li>Search Query for ';
			echo the_search_query();
			echo '</li>';
		}
		elseif (bp_is_user_activity() || bp_is_my_profile() || bp_is_page( BP_MEMBERS_SLUG ) || bp_is_group() || bp_is_page( BP_GROUPS_SLUG ) || bp_is_page( BP_ACTIVITY_SLUG ) || bp_is_page( BP_FORUMS_SLUG )) {
        jm_buddypress_breadcrumb();
		}
	}
	elseif (is_tag()) {single_tag_title();}
	elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "<li>Blog Archives"; echo'</li>';}
	elseif (is_search()) {echo"<li>Search Results"; echo'</li>';}
	echo '</ul>';
}
function buddypress_breadcrumb() {
	global $bp;
$bp_user_link = $bp->loggedin_user->domain;
$bp_user_logout = wp_logout_url( bp_get_root_domain());
global $current_user;
get_currentuserinfo();

   if ( bp_is_my_profile() ) echo '<a href="'.SITE_URL.'/members/">Members</a>';
          if ( bp_is_page( BP_MEMBERS_SLUG ) && !bp_is_user()) echo '<a href="'.SITE_URL.'/members/">Members</a>';
          if ( bp_is_group() ) echo '<a href="'.SITE_URL.'/groups/">Groups</a>';
          if ( bp_is_page( BP_GROUPS_SLUG ) && !bp_is_group() ) echo '<a href="'.SITE_URL.'/groups/">Groups</a>';
          if ( bp_is_page( BP_ACTIVITY_SLUG ) ) echo '<a href="'.SITE_URL.'/activity/">Activity</a>';
          if ( bp_is_page( BP_FORUMS_SLUG )) echo '<a href="'.SITE_URL.'/forums/">Forums</a>';
          if ( bp_is_user_activity() ) echo '<a href="'.$bp_user_link.'">'.$current_user->display_name.'</a>';
}
Advertisements

Page Navigation for the posts

function pagination($pages = '', $range = 5)
{  
     $showitems = 5;  

     global $paged;
     if(empty($paged)) $paged = 1;

     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
     }   

     if(1 != $pages)
     {
         echo "<div class='wp-pagenavi'>";
         echo "<span class='pages'>Page 1 of "; echo $pages; echo "</span>";
        
         if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>Prev</a>";

         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
             }
         }

         if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>Next</a>";  
         
         echo "</div>\n";
     }
}

Call this in your posts archive to display the page navigation.

Post Views Snippets

function setPostViews($postID) {
    $count_key = 'views';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}

Paste the below code in the single page, so that it count your views.

setPostViews(get_the_ID());

Shorten the text length in WordPress

function ShortenText($text,$chars_limit){
// Change to the number of characters you want to display
$chars_text = strlen($text);
$text = $text." ";
$text = substr($text,0,$chars_limit);
$text = substr($text,0,strrpos($text,' '));
// If the text has more characters that your limit,
//add ... so the user knows the text is actually longer
if ($chars_text > $chars_limit){
$text = $text."...";
}
return $text;
}

Display the First image from a Posts

function catch_that_image() {
  global $post, $posts;
  $first_img = get_post_meta($post->ID, 'thumb', true);
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\'
"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  if($output == 1 && empty($first_img)){ //Defines a default image
  $first_img = $matches [1][0];
  }
  else if(empty($first_img) && $output == 0) { $first_img = "no_image_url";
  }
  return $first_img;
}

Remove unwanted HTML Headers from WordPress

// Remove unwanted html header
function remove_header_info() {
    remove_action('wp_head', 'rsd_link');
    remove_action('wp_head', 'wlwmanifest_link');
    remove_action('wp_head', 'wp_generator');
    remove_action('wp_head', 'start_post_rel_link');
    remove_action('wp_head', 'index_rel_link');
    remove_action('wp_head', 'adjacent_posts_rel_link');
}
add_action('init', 'remove_header_info');