Forum Moderators: coopster
First let me say that I am a rank amateur and am learning as I go. That said, I am using a php scripted page to call several different html pages as content. This makes it very easy to edit the look, header, etc...of the 200+ pages on my site but keeps them from having good individual titles that the search engines like.
If I use a "create title" tag I do get individual titles but they show the entire url (http:......com/php?x=....) and I would like plain text in the header. Are there tags I can use on text in the html pages (product names) to extract them to the title?
If so what would I put in the php page to call the title from those tags.
Thank you for any help you can give.
Connie
I'm not quite sure I understand what you are are trying to do here. Are you saying you would like to use PHP to place a unique title on your page based on a name pulled from a database? If so, it would go something like this:
<html>
<head>
// perform query to get product name from database
<title><?php print $title;?></title>
</head>
// more html here...
<edit>edited typos</edit>
[edited by: coopster at 12:50 pm (utc) on Dec. 14, 2003]
Unfortunately I don't have a db or this would be a lot easier. What I would like to do is select text from the html document itself and use it for the page title. The html documents called into the php page are basically just a single table. The first row has a single td which contains the product picture and the product name (I could change this to two separate rows if necessary or rewrite all of the pages to div tags - more work than I would like right now). I would like to tag that product name and use it as the page title. I read in one post to this forum that the image alt tag could be used this way but that the search engines might consider that spam.
Is this possible?
Thanks,
Connie
index.php?page=content.html
==========
include(top.html)
include(leftside.html)
include(content.html)
include(bottom.html)
top.html
==========
All the "top of page" html, such as nav bar and visual headings.
leftside.html
==============
All the code for the left-hand side of the page
content.html
==============
This is the page which I presume will change on a switch in the url. This includes the centre table as explained in her post.
bottom.html
============
All the "page footing" source.
I think the target is, is to have the title tag, which will either be set in the main index.php or in the top.html, to be dynamic depending on which content page is pulled in.
My suggestion: if the content pages (what you include the content on) are PHP, then at the top, include something something like
$title = "Your dynamic title";
For this to work, you would probably have include this file at the beginning, print out the title, then later on, print the rest of the source. Shouldn't be too hard, but depends on how you have your file structure set up. Can you enlighten us any further?
Cheers,
wruk999
It sounds like you want to do this:
Have your master script page search the unique html page for the text to use as a title when it is loaded. The master page would then generate a <TITLE> tag using this text.
If the text you want to use as a title is always in the same cell in a table then the search pattern shouldn't be hard.
((This is not an elegant solution & it would be slow to load but it should work if I understand the problem correctly))
Bob
I think I get it. You have a page which has your <head> tag, and the page with the product info gets included later and is not part of the <head>, so you don't know how to get that info up into the <title>
Before thinking of solutions, how many pages do you have here? In other words, is a hand-edit a reasonable solution are do you need something that will work as you want with the files you've got?
In brief, if the former, you can easily do some sort of simple templating in PHP.
If, on the other hand, you need to keep the files as they are because there are thousands of them, then you may be stuck. If you've already output your <title> tag before you do your include, you will have to rely on Javascript and DOM to go rewrite it... Come to think of it, I bet the title tag can't be rewritten once the page loads, so that won't work either. Not sure about that.... I just spent yesterday creating a script that works in a table such that when you click on text in a cell, it turns it into a <input> and lets you edit and save, but I think the <title> tag may be read only. Anyway, somebody over in the Javascript forum would know a lot more about that than I do.
Tom
So the process is like this:
currently (clumsy pseudo code ahead):
<html>
<title>Generic Title</title>
some html
<?php load('content.html')?>
more html
</html>
new:
<html>
<title><?php extractTitleFromTDViaRegex('content.html')?></title>
some html
<?php load('content.html')?>
more html
</html>
correct? (somebody please fix up the php syntax).
SN
What I was driving at with a templating system was reading the file into a variable, extracting the title and using it, and then plugging that variable into the page a little lower as the content. so in other words never doing an include.
I was thinking that the file would need a $title var to plug into the template, but you have a good point. If the data is uniform enough, you should be able to get it with a regex. Worst case, some pages will have mangled titles and he can fix those as they crop up.
Tom
<?php
$base_dir = 'content/';
ob_start();
if (isset($_REQUEST['x']) and $_REQUEST['x']!='') { // make sure $x is set and has a value
if (file_exists($base_dir.$_REQUEST['x'].'.html')) { // if $x is set, make the file exists
@readfile($base_dir.$_REQUEST['x'].'.html');
$content = ob_get_contents();
ob_end_clean();
} else { // if the file doesn't exist, display the default page
ob_end_clean();
header("http://www.site.com/");
exit;
}
} else { // if $_REQUEST['x'] doesn't have a value or isn't set, display the default page
ob_end_clean();
header("http://www.site.com/");
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link href="styles.css" rel="stylesheet" type="text/css">
<title>some site stuff, more site stuff</title>
</head>
<body>
blah blah layout, nav, images, blah blah blah
<?=$content?>
blah blah more layout, footer, images blah blah blah
All of my html files are in a folder called "content" and the the url would be www.site.com/product.php?x=htmlname
This opens an individual product window and if I have to modify navbars, colors, layout, etc... I only have to do it once. There are about 200 product pages but I'm doing this alone so even though it's not thousands full editing of each page could be time intensive.
The regex function looks like a possible solution. If there is more than one td in the table how do I specify which one the script is to look in?
hope this helps
Connie
-problem with being a newbie is not knowing what questions to ask.
[edited by: jatar_k at 5:37 pm (utc) on Dec. 15, 2003]
[edit reason] generalized urls [/edit]
<head>
<title><?php echo $_GET['title'];?></title>
</head>
with the links being written like so
<body>
<a Href="page.php?x=product&title=Product Name"
</body>
Works great in all the php pages but of course not in the index.html page (which is a separate entity). Not sure if I want to change that to php because it would render all my inbound links useless.
Any suggestions there?
Connie