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}">
Ginnunga Gaming
[Updated on: Mon, 25 October 2010 12:17] Report message to a moderator
|
|
|
|
|
|
|
Re: Dynamic forum META description [message #163395 is a reply to message #163392] |
Mon, 25 October 2010 15:23 |
Ernesto
Messages: 413 Registered: August 2005
Karma: 0
|
Senior Member |
|
|
I think we only read the first message from the disc twice, right?
We read it once in my code above (only reads if $obj->root_msg_id == $obj->id IE only if the message is the first message in a thread)
and
We read it in dramsg.tmpl -> dmsg_normal_message_body with {FUNC: read_msg_body($obj->foff, $obj->length, $obj->file_id)}
could of course move my code down to where dmsg_normal_message_body is created or something, I don't know, I am not a performance expert hehe.
Why I solved it like I did was because the call for the func to get the message body was done in the template and not in the src file
Ginnunga Gaming
|
|
|