homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

{if} statement to manage meta tags ?
meta tags

 12:30 pm on May 7, 2011 (gmt 0)

Hi, (new here, sorry if in wrong section)

I have a php website script that by default duplicates the same 'Meta Tags' on every page.

I want different meta tags on each page. I have been totally unsuccessful in disabling this so far.

The creator of the script said that this may be possible if I alter the config files and put an {if} statement in the index.tpl file to make the homepage 'meta tags' static on but to use the individual 'meta tags' present on every other page.

I am not a coder, and I have had no further feedback as yet, so am hoping someone here can help me in any way. Would be GREATLY appreciated.




 12:31 pm on May 7, 2011 (gmt 0)

If anyone could help with creating the {if} statement or where the config files may be exactly...it would all help :) Thanks again...Sjj999


 10:19 am on May 8, 2011 (gmt 0)

Unfortunately nobody knows what script it is you are using. So being able to tell you where the config files sit is going to be a problem as they will be files native to your app. They'll most likely sit in a folder called config or includes, or there could just be a file called 'config.php' or 'script-config.php'. It's whatever who made the script called it.

Also it looks like the script uses a some kind of templating system hence the file extension tpl. Again it's likely here that the 'if' statement is not a native php if statement, but something that the template interprets, as such, without really seeing the script in question it will be difficult for some to just stab at it in the dark


 5:04 pm on May 9, 2011 (gmt 0)

The creator of the script said that this may be possible if I alter the config files and put an {if} statement in the index.tpl file to make the homepage 'meta tags' static on but to use the individual 'meta tags' present on every other page.

This would work, but it's a patch . . . when in doubt, look at what Those That Preceded you do, most of them are pretty sharp. Most CMS, cart, bulletin board, or other systems use a substitution method. That is, you have some "placeholder" in your templates. It can be anything, shoot for character combinations that will likely never be encountered in user input. Examples,


<meta name="description" value="[META_DESC]">
<meta name="description" value="|META_DESC|">
<meta name="description" value="{META_DESC}">

Note it's not only the delimiters of the "marker" that are important, the case is too - I use capitals in this example.

Next, your unique data needs to be stored somewhere, right? Wherever the page data is stored, likely in a database entry, you need to add a field for these unique values. Then when you read in the template, you do a str_replace() or preg_replace to swap out the values for the markers.

This is important 101 in developing any scripts, if you're being sold scripts with the same meta info, question your resources.


 5:33 pm on May 9, 2011 (gmt 0)

Hi, just seen your replies, thank you so much Tommybs & Rocknbill.

It is a free script...as I am not a coder, I try to learn as I go, but only with the kind help of people like yourselves!

Rocknbil: I have some "pages" stored in the database and also some "pages" created as .tpl files, so to test, I thought I would try to add to a .tpl file first:

<meta name="description" value="[META_DESC]">

Do I store the unique data in same file ?

Can I press you further to know how I would write this if I wanted the title as "UK Cars" and description "Buy UK Cars" (for example).

Thanks again.


 4:39 pm on May 10, 2011 (gmt 0)

Pages created as template files? Doesn't seem to make a lot of sense. You're creating a new .tpl for each page?

If you are, substitution is really a waste of time, you'd just hard code them in I guess.

A CMS should do something like this.


Here we have a bunch of raw content, it can be in a database as rows of data or files (more unwieldy, but works.) This raw content has no HTML, or at best is very basic <p>'s, <ul/ol><li>'s, etc. This content is as Plain Jane text as possible, and completely devoid of formatting so we can put it where we want it.

Typical fields:
meta_keywords (optional, minor)
widgets (sidebar content, whatever)


There should be only a few templates for any given site (sometimes there are many, but could be very few.) Templates are the formatting. We can now assign the fields to the format, and swap out templates at any time.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>[PAGETITLE] | [SITENAME]</title>
<meta name="Description" content="[META_DESC]">
<meta name="keywords" content="[META_KEYWORDS]">
<link rel="stylesheet" type="text/css" href="/css/mystyle.css">
<div id="container">
<div id="main-left">
<div id="right-sidebar">

There's our formatting. We have separated content from formatting, and CSS separates style from markup.


This is of course the glue that binds the two together, for you, PHP, but it can be any server-side language. Using the script and based on the request, we open the requested content, temporarily hold the values in memory, open the template, insert the content, and output it to the browser.

Does this CMS work in this fashion? Where do all your pieces fit in? In order to answer your last question we have to know where the page data actually comes from.


 3:49 pm on May 16, 2011 (gmt 0)

Hi, thanks again,

I have 3 types of pages created within my site.

1. Some pages are in mysql Database.
Their extension on the website looks like this (example)

2. I also have .html pages with extensions that look like this (example) [mysite.com...]

3. I, however, have also created pages by creating .tpl files and their extensions are [mysite.com...] I created these files (and duplicated and edited some php files) to make them return different search results which was something I was trying to achieve and it worked. My signup and other pages are created this way with .tpl (& php) files.

My homepage (index.tpl) originally had the following code in (..which, I cant remember why, I took out and added normal meta tags <title> My site</ title> desc, etc tags...(perhaps it should go back?). If I put back the code below you can add and edit these tags in the admin area of the script.

{if $title != '' }
<title>{$title} {if $page_title ne ""}- {$page_title}{/if}</title>
{elseif $config.site_title ne '' }
<title>{$config.site_title|stripslashes} {if $page_title ne ""}- {$page_title}{/if}</title>
<title>{lang mkey='title'} {if $page_title ne ""}- {$page_title}{/if}</title>
<meta http-equiv="Content-Type" content="text/html; charset={lang mkey='ENCODING'}" />
<meta name="keywords" content="{$config.meta_keywords} {$title} {$page_title} " />
<meta name="description" content="{$title} {$page_title} {$config.meta_description} " />
So what would be the best way to create the pages for the seperate meta tags with {if statement}...Method, 1, 2 or 3 ?


Well :/ as you have guessed, I don't have much of a clue...Amazing I have got this far..lol.

Hope now you can help with writing those {if} statements to create different meta tags on each page.

Thanks again :)


 4:05 pm on May 16, 2011 (gmt 0)

Okay, well, it looks like PHP is parsing this file and the conditionals are interpreted by whatever script you are using. Your mission is to find out how these gets populated:


What it's doing is if $title has been set somewhere,

$title = 'Home Page';

it will use that value, otherwise, it **plans** on using the configuration for "site title", whatever that is, UNLESS $page_title has been set

$page_title = 'about us';

Figure that out and you should be able to set unique values for each .tpl.

For others reading as originally asked, and for a frame of reference, does this CMS have a name or is it custom coded?


 11:43 am on May 17, 2011 (gmt 0)

The script is OSDATE dating script, thanks


 4:49 pm on May 17, 2011 (gmt 0)

AH. It's using Smarty templates [smarty.net].

Don't have time to fully explore the issue (and haven't used Smarty,) but you can start with the basic syntax here [smarty.net]. That is version 3, there is a version 2 [smarty.net].


 3:53 pm on May 18, 2011 (gmt 0)

Thank you Rocknbil,

I really do appreciate you taking the time.

If I get anywhere with it...I will let you know :) Thanks again.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved