Forum Moderators: coopster
index.php?page=somepage Now, my problem is the way I call titles. I want to include a title from my pages (located in a directory "/pages"> - but it's not working as I hoped it would.
See, I'm trying to be clever, maybe too clever. On the index.php page, I'm including my header.htm with
<HTML><HEAD><TITLE><?=$title?></TITLE></head>, then the main script, and then the footer.htm, but instead of putting my page title on the index page which calls the content pages, I want to include it from the pages being called. Which, as I'm sure some of you know, doesn't work (I've learned that!). Just wondered if anyone knew a way PAST this somehow? I've spent a week trying to figure out how to get past this... it's probably pointlessly easy and I'm missing something, but I can't see it. I know I can add an extra tag onto my links to change page titles, but I just find that an extremely fussy way of doing this. I just want to include the page title in the pages I'm calling.
or am I just overcomplicating the whole thing?
<?
include("/pages/somepage.php");
if (!isset($title) ) $title = 'Index.php Title Here';
echo "<title>".$title."</title>";
?>
On second, thought since this depends on the page variable, something like this might be more efficient:
/header.htm
<?
include("/pages/" . $page); //load the page from the current var in the url
if (!isset($title) ) $title = 'Index.php Title Here';
echo "<title>".$title."</title>";
?>
<?
$title="somepage title";
?>
Hopefully that leads you in the right direction!
Currently, my index.php page is set up as such:
<?php
include ("theme/header.htm"); (page calling script)
include ("theme/footer.htm");
?>
Now, this WILL WORK if I call the page title as such:
<?php $title="My Page";
include ("theme/header.htm");
(Script)
include ("theme/footer.htm");
?>
But with this method, all the pages processed by index.php will bear the same title - which isn't what I want.
What I want to happen is to include the title INTO the page being called - say,
(somepage)
<?php
$title="My Page";
?>Content goes here.
But I'm fast realising that it's not straight-forward getting a title from a called page.
SO, basically, I got an index.php page - to which is called header.htm, a specifed page set by the url (?page="somepage"), and footer.html. I want to shift the $title from index.php to mypage...
See, I thought this would be straight-forwards, by just including the $title tag into the page being called, and thought (hoped) that it would still work. But it doesn't.
Err... and thats pretty much it... am I making a meal out of this or what? Sheesh, even I know I'm making this far too complicated...
Basically - I want to set my page title in the pages being called. There. Phew.
<?php
$title="index title";
include ("theme/header.htm");
//which has a line like
echo "<title>".$title."</title>";//now use your script to call the specific page (somepage)
//now title is set as:
$title="page title";
//but..title has already been defined earlierinclude ("theme/footer.htm");
?>
<title>index page</title>
<?php
$title="index title";
if ($page) {
include ("/pages/".$page);
}
//now the title has been redefined as PHP should see:
$title="page title"; //from the current file//now we include the header
include ("theme/header.htm");
//which has a line like
echo "<title>".$title."</title>";//now call the specific page as usual
//and include the footer
include ("theme/footer.htm");
?>
Now the page title in the above code would be:
<title>page title</title>
On a side note, are you using MySQL or some other database to store your information? It would be a bit easier to get the title for the current page if you just called the proper table/row from the db and then grabbed the title cell beforehand. Then you wouldn't have to worry about ever having the same title (unless of course you wanted to :) ). And you could setup a default page title too, if no title is specified.
Thanks for your help. SQL is the next step but I wanna be sure I can work this out and understand it before charging off into something else. Thats just the way I learn.
Brace yourselves for the most obvious solution...
I moved my title/header/footer tags into the pages being called. Bingo. So all the index page does now, is call the pages.
See. It takes a huge clout to the head to see the obvious route (I mean that literally. Stupid shed roof caved in on me earlier...)...
It's probably not the cleanest or efficient method... but it works.
I do the same but I also use a default. Pages with a specific title will look like so
<?
$title = "some fancy title";
include "header.php";
etc....
then in the header I use
if (!isset($title) ¦¦ $title == "") $title = "very generic title";
echo "<TITLE>",$title,"</TITLE>";
simplified obviously ;)
Thanks for the heads up guys on setting a default title should a page name NOT be specified. Big help, and more info then I really needed but extremely useful to know! :)
Again, thanks for the heads up on the different ways of doing this. Much appreciated.