Forum Moderators: coopster
Basic info: we use Macromedia studio 8 and notepad++ to do all our design and coding work, no special CMS, just write it, test it on a local server, and put it on the web. The basics of our site are set up (long ago by professionals) to use all possibilities of dynamic sites and MySQL, but in reality at this moment, we use hardly any of that, not even a database or “includes”. Database will come in the near future.
Our index.php is the main container with the header, sidebar navigation (including bot-trap), and footer already on the page. Index.php has the doctype and head stuff (meta tags, title, css, etc) and uses php to fill the body-content part of the container. We do not have additional header.html or footer.html pages as includes; they are pictures (header.jpg, body-bottom.jpg) defined in the CSS file. The body-content files have only pure body content, nothing else, no coding. View Source Code of our site for the complete setup.
All works a treat and looks ok, and our target group (mostly older people; using older computers and not happy with too flashy or slow pages) like what they see and how it works. That is, if they can find us because we did not pay enough attention to SEO and SEF.
Individual page titles. Read many treads on this already, none of them really giving a solution that works for us. What I am wrestling with is to keep everything inside the index.php but maybe I need an include file to help solve this. What I tried are several variations of what I found on [webmasterworld.com...] at the end of that tread:
<head>
<title><?php echo $_GET['title'];?></title>
</head>
with as response part:
<body>
<a Href="?act=x” &title=”pagetitle"
</body>
I also tried putting the $title somehow in the ?php…GET..…? section, in line with the require command, which would be the nicest solution. Or in the beginning of a body content page. No dice, it did not work.
Is it possible to make this work at all, maybe with an include file defined completely at the beginning of the index.php, or will this never work and do I have to restructure this and our other five websites to get individual page titles?
[edited by: jatar_k at 1:13 pm (utc) on April 15, 2008]
[edit reason] no urls thanks [/edit]
You can use an if statement construct and use some code to discover what page you are on and add the title to suit:
$page_title = '';
if (strpos($_SERVER['PHP_SELF'],'contact.php')!==FALSE) {
$page_title = 'Contact Page';
}
if (strpos($_SERVER['PHP_SELF'],'about.php')!==FALSE) {
$page_title = 'About Page';
}
if (strpos($_SERVER['PHP_SELF'],'services.php')!==FALSE) {
$page_title = 'Services Page';
}
<title><?php echo $page_title; ?></title>
Hope that helps. Or did I misunderstand what you are trying to do?
dc
In the first post I mentioned the <title><?php echo $_GET['title'];?></title>. With that one, I put the associated page titles inside the <?php..?> section, without further statements. Probably I should have included also something like
if(isset($_GET['title'])){
switch ($_GET['title']) {
but I did not know how and where to do that or how to link that to the $_GET['act'] section.
I think showing the index.php layout might help clarify our site’s dynamics (or lack of it). Deleted not-relevant parts. Dreamcatcher, your suggestions are mentioned also, maybe I put them in the wrong places?
index.php
******
<?php
//**Place for title function lines. Until now empty?**//
$page_title = '';
if (strpos($_SERVER['PHP_SELF'],'about.php')!==FALSE) {
$page_title = 'About us';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="cz">
<head>
<meta 'Content-Type' & 'Content-language' & <meta name="Author"
<meta name="description" content="blab la bla" />
<meta name="keywords" content=" bla, bla" />
<title><?php echo $page_title; ?> </title>
//** earlier I tried <title><?php echo $_GET['title'];?></title> **//
<link href="css/fors.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="main">
<div id="header"></div>
<div id="sidebar">
//**All the sidebar text and links are here, for example**//
<li><a href="?act=14">About us</a></li>
</div> --end of sidebar.
<div id="body content">
//**this is the dynamic part getting the body content files**//
<?php
if(isset($_GET['act'])){
switch ($_GET['act']) {
//**Here are all the names and locations of the body content files, for example**//
case "14":require("./about.php"); break;
default: require("./intro.php");
}
}
else {
require("./intro.php");
?>
<div id="body_bottom">
//**Text of body bottom for all pages**//
All closing codes </div>, </body>,</html>
*****
end of index.php
Hopes this makes it clearer, any suggestions?
$page_title = '';
if (isset($_GET['act'])) {
switch ($_GET['act']) {
case '14':
$page_title = 'About Us';
break;
}
}
echo $page_title;
dc
Took some time to get something working, but finally managed some results maybe usable for debugging. However, biggest problem is that this maybe can be made to work and echo a title on the page itself, but the page source view shows that the “title” in the title bar (and in the SER) has become some kind of table (probably from debugging program?) with the remark … “Notice: Undefined index: title in C:\apache\htdocs\www\index.php on line 10“..
I tried this:
<head>
<title><?php echo $_GET['title'];?></title>
</head>
And in the php part:
<?php
$title = '';
if(isset($_GET['act'])){
switch ($_GET['act']) {
Variations tried out:
case '14': $title='About us'&require("./about.php");break;
This loads the page but ignores the page title.
case '14': require("./about.php")&$title='About us';break;
This gives a fatal error “Failed opening required '' (include_path='.;C:\php5\pear') in C:\apache\htdocs\www\index.php on line 95”
Separating title and require using two times case'14'
case '14': &$title='About us';break;
case '14': require("./donations.php");break;
OR
case '14': &$title='About us';break; (no “require” action)
Parse error: syntax error, unexpected '&' in C:\apache\htdocs\FORS-domain\www\index.php on line 95
Managed one time to get it to echo only the “about us” but not load the page, but could not redo that and forgot to write the combination when that occurred.
Regardless, all variations do not result in a clear and nice title output for the <title> section, which is what I need.
With the whole <?php...?> section way below the </head> section, would not be any response from the php section be too late to rewrite the title, that is, the title or whatever it can pull into it gets written and prepared before the php function in the body gets active?
If you would make an include file at the complete beginning of the index.php, with a for each important page a separate page title and description, how would google crawl this? Would that bot just run through the different title-description combo's until it reached one that fits its query, and then display that as result?
With unique page titles and related page file names and H1 page headings, how much added value you get from also trying a trick to change our dynamic URLs into static URLs? To be clear, I am only concerned about SEF for bots; for our target group, it does not matter if they see ../about.html or .../?act=1
I can`t really see why the code isn`t working. Seems like it should be ok. Obviously your setup is working differently to how I think.
dc
I also don't know why it does not work. What might be confusing is that everything is happening inside the index.php file. That file has everything, it calls no includes or anything except CSS and body-content pages. The body-content pages are without any coding. So the order in which the functions work is crucial.
Somebody of another forum gave me and elegant solution. I extended that to include also meta-description and meta-keyword, which I am testing now. If completed and functional, I will come back to it here. I posted the link to the solution here, hope that is not in violation of the rules.
<snip>, the solution is completely at the end of page 3, with another tweak at the beginning of page 5.
Initially, it did not work because my home server (apache 2.2 - php 5.2.5) did not accept the <?= $page_title ?> shorthand but with <?php echo $page_title ?> it worked.
[edited by: dreamcatcher at 2:03 pm (utc) on April 20, 2008]
[edit reason] no urls, thanks. [/edit]