Forum Moderators: coopster
------------------- code ------------------------
<html>
<head>
<title>None</title>
</head>
<?php @ require_once ("structure/bodynav.php"); ?> <ul id="menu"> ------------------- end of code ------------------------ Any help is much appreciated :)
<? $path = $_SERVER['PHP_SELF'];
$page = basename($path);
$page = basename($path, '.php');
$query = $_SERVER['QUERY_STRING'];
$query = explode('=', $query);
$query = $query; ?>
<li><a href="about.php?page=home" <? if($query == home) print ' class="current"'; ?>>Welcome</a></li>
</ul>
<div id="content">
<?php if (isset($_GET['page'])) {include 'content/'.$_GET['page'].'.htm';} else {include 'content/services.htm';} ?>
</div>
<?php @ require_once ("structure/footer.htm"); ?>
[edited by: tedster at 12:21 am (utc) on Mar. 2, 2009]
[edited by: Nealreal at 12:27 am (utc) on Mar. 2, 2009]
In your case you would need to do something like this:
<title><?php echo $document_title_tag; ?></title> You would need to store the titles somewhere and have some sort of logic that selected the correct one. This would happen above/before the DOCTYPE is sent. You then simply echo it into the title tag later.
<title><?php echo $document_title_tag; ?></title>
But what do I put on the actual pages that will be included into the template?
Other post have given 2 junks of code:
1) for the template
2) for the actual pages that's being included
Your post doesn't help me.
[edited by: Nealreal at 3:14 pm (utc) on Mar. 2, 2009]
<html> <head> <title><?php echo $document_title_tag; ?></title> </head> <body> and your document page could look something like this...
<?php $document_title_tag = 'Blah Blah'; require_once ("structure/bodynav.php"); ?>
<h1>Page title</h1> <p>Blah blah blah</p> <?php require_once ("structure/footer.php"); ?>
-----------------------------------------------------------
Notice:Undefined variable: document_title_tag in C:\wamp\www\about.php on line 6
-----------------------------------------------------------
This is a same error I got before from another post solution online.
<div id="content">
<?php if (isset($_GET['page'])) {include 'content/'.$_GET['page'].'.htm';} else {include 'content/services.htm';} ?>
</div>
<div id="content"></div> is where the pages are loaded into.
"content/services.htm" is the content file that I need to have a TITLE KEYWORDS and DESCRIPTION for and it should replace the TITLE KEYWORDS and DESCRIPTION in the 'about.php" template's page.
the first thing that your code does is load the "structure/bodynav.php" page -- which asks for the value of $document_title_tag.
But you do not set the value of $document_title_tag until further down your original code (when you load the "content/services.htm" page).
that is why you are getting your error -- you are trying to write it out before you even know what it is.
you need to set the value of $document_title_tag before you load "structure/bodynav.php".
the easiest way to do it is to set all the values at the top of the "about" page, and then load the templates further down. not sure why you really need that other page called "content/services.htm", because you can set the values on the "about" page.
so your "about" page would look something like this...
<?php $document_title_tag = 'Blah Blah'; $document_meta_description_tag = 'Blah Blah' $document_meta_keywords_tag = 'Blah Blah' [/code]
[code]include ("structure/bodynav.php"); ?> [/code]
[code]<h1>Blah Blah</h1> [/code]
[code]<?php include ("structure/footer.php"); ?> all that basename stuff you've got on your original post is a bit more complicated than it needs to be. if you are trying to set up some kind of navigation that changes depending on which page it's on, then all you've got to do is include some kind of "template/navigation.php" page with this...
if(basename($_SERVER['SCRIPT_NAME']) == 'blah.php') { Do one thing } elseif(basename($_SERVER['SCRIPT_NAME']) == 'blahblah.php') { Do another thing } else { Do default thing }
That's what I was saying, above.
You'll need to re-organise the way you do things. The best way is to have all your PHP code that fetches and assembles the content placed before the point that you send the DOCTYPE out to the browser.
After the DOCTYPE you then simply ECHO out the pre-assembled headers, navbar, content, to the browser. That is, there is no fetching or logic decisions after the DOCTYPE, just ECHOing of the content that you have already assembled before you sent the DOCTYPE out.
Say someone asks for a page using a URL that doesn't exist for any valid content on your site. Assume that the way your script is programmed, that you have sent the DOCTYPE out before you have even checked that there is actually real content to be served for this URL.
It is now too late to send a HEADER 404 NOT FOUND response back for that request. That is, every URL requested from your your site, even random gibberish URLs, will serve the basic template layout, with a 200 OK response, and no content on the page. That's a major problem and a Duplicate Content issue.
How can this happen? For example, should you ever 'delete' a page, search engines would continue to index a blank template at that URL instead of receiving the proper 404 response that tells them the page has gone. The 200 OK response tells them that this *is* a real page, even when it isn't.
So, later on in your PHP experiments, you'll one day see the need to sometimes use the HEADER command to send a 301 or 404 response out instead of sending readable content - and the way that HTTP works, you MUST send that HEADER out before you send any DOCTYPE or on-page content. That can only be done if all the logic that assembles the page happens before the point you start sending anything out to the browser.
So, the order of stuff in your script should be:
- initialise variables
- fetch data and content that will later populate the page
- decide whether to send an error message (like 404), or a redirect to another URL, or real content.
- Send HTTP headers if anything other than "200 OK" is required.
- Send DOCTYPE for start of document.
- Send HTML header (title, meta description, etc).
- Send page content (header, navbar, content, etc).
website.com/about.php?page=company and if I want to load another page into the about.php the URL would change and so would the content - example:
website.com/about.php?page=services The problem is the TITLE KEYWORDS and DESCRIPTION stay the same because its coded on the about.php page. How can I get the TITLE etc in the about.php template to change when a new link is loaded. Is there a way to add some title codes to the htm file itself and it would replace the TITLE in the about.php page? I have it set this way because ABOUT is a section with sub pages like "company" or "services".
You will have to reorganise the whole thing to incorporate this.
What does your site show if I ask for
website.com/about.php?page=123abc567qwerrty ? I will probably have to post another question in the forum for the other features that i will loose by changing my organization.
Thanks for your help. I'll be back.