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?
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
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 . ', ';
} "/>
can you post the whole block?
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: } "/>
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>';
Aha..thanks man..it works. This schould to to the tips and tricks. It's a quite important seo stuff ;)
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.
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.
OK no prob...take you time...
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>';
Ok changed..will se if i get any error ;)
-------------
Update
------------
No error till now. Thanks ;)
This think schoudl definataly go to tips and trics