FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Plugins and Code Hacks » Dynamic forum META description
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Dynamic forum META description [message #163381] Mon, 25 October 2010 11:45 Go to previous message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma:
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

[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: BBcode for H1-H4
Next Topic: Useful function when there are still some ISO-8859 chars in the UTF8 database stored messages
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 15:06:16 GMT 2024

Total time taken to generate the page: 0.04675 seconds