mw_get_post_info can return any or all of the word and image counts, a list of the post's categories, and comment/ping status for current post. Accepts two parameters: a series of letters that define the order of what's shown, and the separator character to put between each of the bits of information (' | ' by default; note the spaces). Also contains the function the_plain_categories, which returns the post categories in plain text with an optional separator (' ' by default, or a single space).
Version: 1.0.1
Date: 9 July 2004
Author: Eric A. Meyer
Author URI: http://meyerweb.com/
*/
function mw_get_post_info($show='WICR', $separator = ' | ') {
global $post, $wpdb, $tableposts, $id;
$ret = '';
for ($i = 0; $i < strlen($show); $i++) {
$symb = substr($show,$i,1);
switch ($symb) {
case 'W':
$words = strip_tags($post->post_content);
$words = preg_split('/\s/ ', $words);
$wordcount = count($words) - 1;
$wordcount = $wordcount;
$ret .= number_format($wordcount) . ($wordcount==1 ? " word " : " words") . $separator;
break;
case 'I':
$imagecount = preg_match_all("(
post_content, $images);
if ($imagecount != 0) {
$ret .= $imagecount . ($imagecount==1 ? " image" : " images") . $separator;
}
break;
case 'C':
$ret .= the_plain_categories() . $separator;
break;
case 'R':
if ($post->comment_status == "open" && $post->ping_status == "open") {
$ret .= "comments and pings allowed" . $separator;
}
if ($post->comment_status == "open" && $post->ping_status != "open") {
$ret .= "posted comments allowed" . $separator;
}
if ($post->comment_status != "open" && $post->ping_status == "open") {
$ret .= "pings allowed" . $separator;
}
if ($post->comment_status != "open" && $post->ping_status != "open") {
$ret .= "no comments allowed" . $separator;
}
}
}
return substr($ret, 0, -strlen($separator));
}
function the_plain_categories($separator = ' ') {
$catlist ='';
$categories = get_the_category();
foreach ($categories as $category) {
$category->cat_name = stripslashes($category->cat_name);
$catlist .= $category->cat_name . $separator;
++$i;
}
return substr($catlist, 0, -strlen($separator));
}
?>