Hi all, I’m designing my page using one page, kind of. I have a switch statement on my index.php page which includes the relevant page depending on the URL. Having an issue with the head section. By head section in included in the function ‘globalAssets’ - though my switch statement is below this so therefore my page names, etc are not displaying in the head.
What’s the best way to get around this? Below is all of my code from my index.php page.
<?php
include('includes/config.php')//The function globalAssets is created in this file;
globalAssets() //My head section is included within this function;
?>
<body>
<!-- BOF Wrapper -->
<div id="wrapper">
<!-- BOF Header -->
<?php include('includes/nav.php'); ?>
<!-- EOF Header -->
<?php
switch($_GET['main_page']):
case "lists":
include('includes/listpage.php');
break;
case "product":
include('includes/prodinfo.php');
break;
case "cart":
include('includes/cart.php');
break;
endswitch;
include('includes/footer.php');
?>
</div>
<!-- EOF Wrapper -->
</body>
</html>
@Mandes you are right, but that guy is a newbie so he may not get it if we write in words… I’ll try to put it in form of code after testing it on my local wordpress
Hey dudes, thanks for your messages. The only thing that would be changing in my head is the page title, meta-description and meta-keyboard…nothing else would change so would this still be the best solution to this problem?
Hi Mandes, I agree, I didn’t quite class myself as a newbie really anymore, still learning, but think that’s something many developers find - when do you ever stop!?
Sure thing, my function is below:
function globalAssets(){
include('includes/head.php');
include('includes/connection.php');
}
My head file is as below, actually not liking it being included, could get complicated, may just incorporate this directly into the function. Anyhow, here is the current head.php contents:
Definitely, I’ve slightly over-complicated things. I’ll indeed make those changes to try and simplify things slightly. So once this has been re-jigged, how would I manage to change the page title if the included files are still below the head section?
However if I was doing this myself Id go one stage further and include the header in the individual page files, that way all the info for the page would be in one php file. and you only have one switch statement
your index.php
<?php
include('includes/connection.php'); // get connection
session_start(); // sort sessions
if(!$_SESSION['SESS_ID']){
$_SESSION['SESS_ID'] = rand();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php // select page contents
switch($_GET['main_page']):
case "lists":
include('includes/listpage.php');
break;
case "product":
include('includes/prodinfo.php');
break;
case "cart":
include('includes/cart.php');
break;
endswitch;
?>
Then your individual php page files starting with the html tag
Hi Mandes, thank you for your indepth reply, makes a lot of sense. I think you are right, I’ll restructure my code slightly, better to get it right now before the site expands any further. Thanks again, have a good afternoon