Generate Meta Desc from Post Content and Comment

edited December 2011 in Feedback

Change in function DiscussionController_Render_Before

from this:

`

    array_walk($tags, 'strip_tags');
    array_walk($tags, 'trim');
    array_walk($tags, 'htmlspecialchars');
    $tags = array_unique($tags);
    if ( count($tags) > 0 )
    {
        $Sender->Head->AddTag('meta', array('name' => 'keywords', 'content' => implode(', ', $tags)));
    }       

    $Sender->Head->AddTag('meta', array('name' => 'description', 'content'=> $Sender->Data('Discussion.Name')));

    $data = array (
        'title' => $Sender->Data('Discussion.Name'),
        'category' => $Sender->Data('Discussion.Category'),
    );

    $type = 'discussion_single';        
    $this->ParseTitle($Sender, $data, $type);`

to this :

array_walk($tags, 'strip_tags');
array_walk($tags, 'trim');
array_walk($tags, 'htmlspecialchars');
$tags = array_unique($tags);
if ( count($tags) > 0 )
{
$Sender->Head->AddTag('meta', array('name' => 'keywords', 'content' => implode(', ', $tags)));
}

    $PageNum = ($Sender->Pager->Offset / $Sender->Pager->Limit) + 1;
    if($PageNum > 1){
    $CommentData = $Sender->Data('CommentData')->Result();
    $Description = strip_tags($CommentData[0]->Body);
    } else {
    $Description = strip_tags($Sender->Data('Discussion.Body'));
    }
    if(strlen($Description)<1){
        $Description = $Sender->Data('Discussion.Name');
    } else {
        $Description = explode(' ', $Description);
        $Description = array_slice($Description,0,40);
        $Description = implode(' ',$Description);
    }

    $Sender->Head->AddTag('meta', array('name' => 'description', 'content'=> $Description));

    $data = array (
        'title' => $Sender->Data('Discussion.Name').' - Page '.$PageNum.' ',
        'category' => $Sender->Data('Discussion.Category'),
    );

    $type = 'discussion_single';        
    $this->ParseTitle($Sender, $data, $type);</code>

Modify for :

  • Generate Meta Desc from Post Content

  • If not first page of Discussion will grab from first comment data in that page

  • Change to Title Tag to add Current Page Number of Discussion

hope, this will be useful for someone

Tagged:
Sign In or Register to comment.