Word Count
-
Open b2templates.funtions.php and find this in your POST TAGS section, it’s around line 599 depending on the hacks you already have in there:
function get_the_content($more_link_text='(more...)', $stripteaser=0, $more_file='') {
global $id,$postdata,$more,$c,$withcomments,$page,$pages,$multipage,$numpages;
global $HTTP_SERVER_VARS, $preview;
global $querystring_start, $querystring_equal, $querystring_separator;
$output = '';
if ($more_file != '') {
$file=$more_file;
} else {
$file=$HTTP_SERVER_VARS['PHP_SELF'];
}
$content=$pages[$page-1];
$content=explode('<!--more-->', $content);
if ((preg_match('/<!--noteaser-->/', $postdata['Content']) && ((!$multipage) || ($page==1))))
$stripteaser=1;
$teaser=$content[0];
if (($more) && ($stripteaser))
$teaser='';
$output .= $teaser;
if (count($content)>1) {
if ($more) {
$output .= ''.$content[1];
} else {
$output .= '<span id="varP'.$id.'">
read more »</span><div id="varXYZ'.$id.'" style="display: none">'.$content[1].'
« hide more</div>';
}
}
if ($preview) { // preview fix for javascript bug with foreign languages
$output = preg_replace('/\%u([0-9A-F]{4,4})/e', "'&#'.base_convert('\\1',16,10).';'", $output);
}
return($output);
}
And insert this right after that:
function get_words() {
$content = get_the_content($more_link_text,$stripteaser,$more_file);
$content = convert_bbcode($content);
$content = convert_gmcode($content);
$content = convert_smilies($content);
$content = convert_chars($content,"html");
$stripper = "";
$wordcount = strip_tags($content,$stripper);
$wordcount = explode(" ",$wordcount);
$wordcount = count($wordcount);
echo "$wordcount words in this post";
}
Call this function in your index.php with:
<?php get_words()?>
- The topic ‘Word Count’ is closed to new replies.