Tuesday, 22 February 2011

Wordpress add small description in the index page or the page you want to show

This is the function in your template function.php

if(!function_exists('getPageContent'))
{
function getPageContent($pageId,$max_char)
{
if(!is_numeric($pageId))
{
return;
}
global $wpdb;
$nsquery = 'SELECT DISTINCT * FROM ' . $wpdb->posts .
' WHERE ' . $wpdb->posts . '.ID=' . $pageId;
$post_data = $wpdb->get_results($nsquery);
if(!empty($post_data))
{
foreach($post_data as $post)
{
$text_out=nl2br($post->post_content);
$text_out=str_replace(']]>', ']]>', $text_out);
$text_out = strip_tags($text_out);
return substr($text_out,0,$max_char);

}
}
}
}


and just have the code where ever you want to have

<....?php echo getPageContent(39,65); .....?>
39 is the page ID

and 65 is the character set

No comments:

Post a Comment