I converted my simple website to PHP, using an include for the header, etc. Can someone show me how to write the code for a loop so that the web page title reflects the proper page, not just the Home page. I did a search and haven’t found anything. I’m assuming this is just a couple lines of code. My site is placetrenddata.com. Thank you.
There are a couple of different ways and the simplest would be to use switch.
Use a variable something like $page = ‘index’; $page = ‘contact’; etc. at the top of each page.
In your include page use:
switch ($page) {
case 'index':
$title = 'Index page';
$metatag = 'Some metatags';
break;
case 'contact':
$title = 'Contact us';
$metatag = 'Some metatags';
break;
default:
$title = 'Index page';
$metatag = 'Some metatags';
}
Then in your pages have:
<title><?php echo $title; ?></title>
You can use the same method for the meta tags etc.
Thanks. I look forward to checking it out.
Nice site, I like the colour scheme.
Thank you very much.
1 Like
Thank you, I figured it out.
Well done, but tell us how you did it.
Sure, I followed Rubble’s directions exactly. I put the below statement in my header include page.
<title><?php echo $title; ?></title>
1 Like
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.