Forum Moderators: coopster
Been left with a site with no SEO or page title work being completed. Am trying to generate the page titles from the pages being called up by through the index page.
In the index page, I am calling up a config file which amongst other things is hopefully defining page titles and meta content, like so (names have been changed to protect the innocent) -
/* page title contents */
$contactus = array("title"=>"Kev's Motto Transport - Contact Us","metaContent"=>"Kev's Motto transport rocks Pesoe forever.");
I would then define the title and meta content in this way for every page on the site.
Then I run another file which should pull this information out when the Contact Us page is called, like so -
<?php
if(isset($_GET['page']))
{
$page = $_GET['page'];
$title = $titleByPage["$page"]["title"];
$metaContent = $titleByPage["$page"]["metaContent"];
}
?>
which should then be placed in the title section, of the index page which looks like this -
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?=$title?></title>
<meta content="<?=$metaContent?>" name="description" >
I just can't get that predefined info in that page :(
The site doesn't error, it just has no title or meta descriptions when I try to do this.
Can anyone tell where I am going wrong?
(then there are sub pages, I guess that is a whole other kettle of fish)
Regards,
Kahuna
I may be tired, so that may be why I'm having difficulty understanding this. So you have a config file, with an array for each page that has the title and meta content for that page?
Is there a reason you're passing the filename through a url parameter? This can be achieved other ways, unless you have some sort of page builder that functions off the index only.
It seems as though either your if statement isnt trapping the name properly, or the arrays set in the config file arent being passed onto the current script properly.
Please write back with a few more details - thanks :)
[webmasterworld.com...]
Thanks for the interest. That is exactly the case there is a single index page, which build the pages dynamically. Pulling in headers, pages, sub pages and footers etc.
Different templates for different data that is being displayed. In similar function or fashion to the link above.
If you can suggest a simpler way that would also be very helpful.
For this reason the index page is currently the only page registering, as the other pages and sub pages are built into the index page. So the page title is established from the index page.
Therefore I want create the page title from the predefined array in the config file for the pages, from the URL parameters
But then you're using a different variable name:
$title = $titleByPage["$page"]["title"];
Is that an error in placing the script here, or did you intend:
$title = $contactus["$page"]["title"];
As I understand -
$titlebypage is referring to the predefined array $contactus in this case, which is identified dynamically using the GET function.
If I put $contactus into the code then all the pages on the site would have the $contactus title as defined in the config file, because all the pages are created through the index pages.
where I am proposing having an array for each page to define the title and meta description.
Is there a simpler way of doing this?
or is $titlebypage the wrong way of calling up the array information defined in the config file?
you can use this syntax:
$page = $_GET['page'];
$title =${$page}['title'];
$metaContent = ${$page}['content'];
Is that what you're after?
Thanks for your help.
I was omitting another array which was $titlebypage
which defined the connected the $page = $_GET['page']; to the $contactus array.
That really was my bad should have looked into the syntax better.
Works perfectly now, even expanded it to include the dynamic pages and using info from the SQL db.
Regards,
Kahuna
Regards,