Page 1 of 1
Seperate Switch Statments
Posted: Sat Apr 10, 2010 3:23 pm
by flight_club
Hi,
I'm somewhat of newb so please forgive me for my ignorance....
In any case, my site currently has a simple php switch statment in the middle of the index.php page which changes the body pages
Here is the code:
Code: Select all
<?php
$url=$_GET['url']; if (empty($url)) { $url='index'; }
changelocation($url);
function changelocation($url) {
switch ($url)
{
case 'index':
include ('main.html');
break;
etc...
}}
?>
The issue is that I would like to have a differnt the header on each page (the purpose is to have different meta data for each page); however, I do not reallly have a clue about going about this as I already have one switch statement. Any help would be greatly appreciated.
Re: Seperate Switch Statments
Posted: Sat Apr 10, 2010 4:07 pm
by requinix
Yeah... Not enough information for us to help.
Kinda seems like you'll have to change the fundamental workings of your site, but just in case you don't, how about posting (a) the rest of the code, and (b) main.html?
Re: Seperate Switch Statments
Posted: Sat Apr 10, 2010 4:17 pm
by lunarnet76
hi,
you should simply do something like
Code: Select all
<?php
$url=$_GET['url']; if (empty($url)) { $url='index'; }
$metaDescription='what i want';
changelocation($url);
function changelocation($url) {
switch ($url)
{
case 'index':
$metaDescription='what i want for the index';
include ('header.html'); // this file contains the html <head> part
include ('main.html');
break;
etc...
}}
?>
and then in your header.html have
Code: Select all
<head><meta name="description" content="<?php echo $metaDescription;?>" /></head>
Re: Seperate Switch Statments
Posted: Sat Apr 10, 2010 4:20 pm
by flight_club
tasairis wrote:Yeah... Not enough information for us to help.
Kinda seems like you'll have to change the fundamental workings of your site, but just in case you don't, how about posting (a) the rest of the code, and (b) main.html?
Hi thanks for the reply I figured it out. For anyone else who has the issue I simply did the following:
Code: Select all
<?php
$url=((isset($_GET['url'])) ? $_GET['url'] : '');
ob_start();
$metadata = changelocation($url);
$content_for_page = ob_get_clean();
function changelocation($url) {
switch ($url)
{
default:
include ('main.html');
return '<meta name="keywords" content="words"/>';
break;
etc...
}}
?>
Then in the <head>
</head>
In the body
Re: Seperate Switch Statments
Posted: Sat Apr 10, 2010 4:22 pm
by flight_club
lunarnet76 wrote:hi,
you should simply do something like
Code: Select all
<?php
$url=$_GET['url']; if (empty($url)) { $url='index'; }
$metaDescription='what i want';
changelocation($url);
function changelocation($url) {
switch ($url)
{
case 'index':
$metaDescription='what i want for the index';
include ('header.html'); // this file contains the html <head> part
include ('main.html');
break;
etc...
}}
?>
and then in your header.html have
Code: Select all
<head><meta name="description" content="<?php echo $metaDescription;?>" /></head>
Thanks lunarnet as well