Home »
FUDforum Development »
Plugins and Code Hacks »
Dynamic forum META description
Dynamic forum META description [message #163381] |
Mon, 25 October 2010 11:45  |
Ernesto
 Messages: 413 Registered: August 2005
Karma: 0
|
Senior Member |
|
|
This is what I just did - check for errors please!
In drawmsg.inc.t add the following at the top of the function tmpl_drawmsg
/* being meta descr hack */
global $thread_meta_desc; // Make the variable global so we can access it from header.tmpl
if ($obj->root_msg_id == $obj->id) // we only grab the message body from the root message of the thread
{
if ($obj->length > 200) // We want our desc to be max 200, seems like a good number
{
$thread_meta_desc_full = read_msg_body($obj->foff, $obj->length, $obj->file_id);
$thread_meta_desc = strip_tags($thread_meta_desc_full);
$thread_meta_desc = substr($thread_meta_desc, 0, 200);
if(substr($thread_meta_desc, 0, strrpos($thread_meta_desc, ' '))!='') $thread_meta_desc = substr($thread_meta_desc, 0, strrpos($thread_meta_desc, ' '));
} else {
$thread_meta_desc = strip_tags(read_msg_body($obj->foff, $obj->length, $obj->file_id));
}
// Lets sanitize the message before we send it to the meta tag
$thread_meta_desc = htmlspecialchars(strip_tags($thread_meta_desc));
if(strlen($thread_meta_desc) < 10) $thread_meta_desc = $obj->subject; // if the message is shorter than 10 letters, we output the threads title as description
}
/* end meta desc hack */
We also have to tweak header.tmpl just a little, we do it like this:
Replace
<META NAME="description" CONTENT="{GVAR: FORUM_DESCR}">
with
<META NAME="description" CONTENT="{IF: $thread_meta_desc}{VAR: thread_meta_desc}{ELSE}{GVAR: FORUM_DESCR}{END}">
[Updated on: Mon, 25 October 2010 12:17] Report message to a moderator
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Tue Mar 11 17:03:47 GMT 2025
Total time taken to generate the page: 0.04661 seconds