Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: rumfa on April 11, 2008, 03:15:36 PM

Title: Put topic name words in a meta name keywords
Post by: rumfa on April 11, 2008, 03:15:36 PM
What is the code i need to put in the <meta name="keywords" content="....." /> so it shows separate keywords from the topic title the user is visiting.
For example. If I am on a topic "who is the best", that in the keywords i get the following words: "who, is, the, best"---> <meta name="keywords" content="who, is, the, best" />

I know you use the $context['page_title'] to show the whole sentence, but how to you separate them with an comma?
Title: Re: Put topic name words in a meta name keywords
Post by: metallica48423 on April 11, 2008, 04:18:04 PM
something like this might do it...


$pieces = explode(' ', $context['page_title']);
foreach($pieces as $piece)
{
        $comma_string .= $piece . ', ';
}


That will store a comma seperated list of the words in $comma_string
Title: Re: Put topic name words in a meta name keywords
Post by: rumfa on April 11, 2008, 04:45:03 PM
Where schould i put it? Between the " " I get an error.

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in .../Themes/newdef112_tp/index.template.php on line 70

The meta name looks like this.
<meta name="keywords" content="$pieces = explode(' ', $context['page_title']);
foreach($pieces as $piece)
{
        $comma_string .= $piece . ', ';
} "/>
Title: Re: Put topic name words in a meta name keywords
Post by: metallica48423 on April 11, 2008, 04:48:21 PM
can you post the whole block?
Title: Re: Put topic name words in a meta name keywords
Post by: rumfa on April 11, 2008, 04:54:30 PM
Sorry

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in .../Themes/newdef112_tp/index.template.php on line 70
61: {
62: global $context, $settings, $options, $scripturl, $txt, $modSettings;
63:
64: // Show right to left and the character set for ease of translating.
65: echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
66: <html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '><head>
67: <meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
68: <meta name="description" content="', $context['page_title'], '" />', empty($context['robot_no_index']) ? '' : '
69: <meta name="robots" content="noindex" />', '
70: <meta name="keywords" content="$pieces = explode(' ', $context['page_title']);
71: foreach($pieces as $piece)
72: {
73:         $comma_string .= $piece . ', ';
74: } "/>
Title: Re: Put topic name words in a meta name keywords
Post by: metallica48423 on April 11, 2008, 05:05:56 PM
Do this:


global $context, $settings, $options, $scripturl, $txt, $modSettings;

        $pieces = explode(' ', $context['page_title']);
                foreach($pieces as $piece)
                {
                        $comma_string .= $piece . ', ';
                }

// Show right to left and the character set for ease of translating.
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '><head>
<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
<meta name="description" content="', $context['page_title'], '" />', empty($context['robot_no_index']) ? '' : '
<meta name="robots" content="noindex" />', '
<meta name="keywords" content="', $comma_string, '" />
<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/script.js?fin11"></script>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
var smf_theme_url = "', $settings['theme_url'], '";
var smf_images_url = "', $settings['images_url'], '";
var smf_scripturl = "', $scripturl, '";
var smf_iso_case_folding = ', $context['server']['iso_case_folding'] ? 'true' : 'false', ';
var smf_charset = "', $context['character_set'], '";
// ]]></script>
<title>', $context['page_title'], '</title>';
Title: Re: Put topic name words in a meta name keywords
Post by: rumfa on April 11, 2008, 05:10:46 PM
Aha..thanks man..it works. This schould to to the tips and tricks. It's a quite important seo stuff  ;)
Title: Re: Put topic name words in a meta name keywords
Post by: rumfa on April 12, 2008, 04:46:39 PM
I get the following arror in my smf list:

8: Undefined variable: comma_string
Datoteka: /home/selovese/public_html/Themes/default/TPortal.template.php (main_above sub template - eval?)
Line: 67


64$pieces = explode(' ', $context['page_title']);
65foreach($pieces as $piece)
66{
67        $comma_string .= $piece . ', ';
68}


Is this because it is a custom name or so and the smf doesn't recognise it? I have something like 6 pages of this errors.
Title: Re: Put topic name words in a meta name keywords
Post by: metallica48423 on April 12, 2008, 04:57:35 PM
im not sure why its doing that... the variable is, without a doubt, defined...

I'll have to look at it more closely when i get home.
Title: Re: Put topic name words in a meta name keywords
Post by: rumfa on April 12, 2008, 04:59:00 PM
OK no prob...take you time...
Title: Re: Put topic name words in a meta name keywords
Post by: metallica48423 on April 13, 2008, 02:34:54 PM
Try this:


global $context, $settings, $options, $scripturl, $txt, $modSettings;

        $comma_string = '';
        $pieces = explode(' ', $context['page_title']);
                foreach($pieces as $piece)
                {
                        $comma_string .= $piece . ', ';
                }

// Show right to left and the character set for ease of translating.
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '><head>
<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
<meta name="description" content="', $context['page_title'], '" />', empty($context['robot_no_index']) ? '' : '
<meta name="robots" content="noindex" />', '
<meta name="keywords" content="', $comma_string, '" />
<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/script.js?fin11"></script>
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
var smf_theme_url = "', $settings['theme_url'], '";
var smf_images_url = "', $settings['images_url'], '";
var smf_scripturl = "', $scripturl, '";
var smf_iso_case_folding = ', $context['server']['iso_case_folding'] ? 'true' : 'false', ';
var smf_charset = "', $context['character_set'], '";
// ]]></script>
<title>', $context['page_title'], '</title>';
Title: Re: Put topic name words in a meta name keywords
Post by: rumfa on April 13, 2008, 03:04:01 PM
Ok changed..will se if i get any error ;)
-------------
Update
------------
No error till now. Thanks ;)
This think schoudl definataly go to tips and trics