Welcome to WebmasterWorld Guest from 107.20.34.173

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

how to create dynamic titles with PHP

     

paff3

7:43 pm on Jan 10, 2003 (gmt 0)

10+ Year Member



Hi.Can i somehow make something like that:the title text is got somwhere inside body text.

korkus2000

7:43 pm on Jan 10, 2003 (gmt 0)

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I don't understand.

paff3

7:51 pm on Jan 10, 2003 (gmt 0)

10+ Year Member



The script that makes me different title for each page and got the title text from somwhere inside <body></body>

korkus2000

7:54 pm on Jan 10, 2003 (gmt 0)

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



What language are you using? ASP, PHP, JSP?

paff3

7:55 pm on Jan 10, 2003 (gmt 0)

10+ Year Member



PHP is the language available for me.

rogerd

8:01 pm on Jan 10, 2003 (gmt 0)

WebmasterWorld Administrator rogerd is a WebmasterWorld Top Contributor of All Time 10+ Year Member



paff, I'm no PHP expert but my guess is you'll have to restructure the code to put the head in the dynamic section, i.e., instead of generating the head and the top of the page, then doing all the dynamic stuff, you'll have to get the dynamic info first and then write the whole page.

paff3

9:15 pm on Jan 10, 2003 (gmt 0)

10+ Year Member



I didnt understand.Anyway would it be too big loss if i put same title for every page?

Finder

10:03 pm on Jan 10, 2003 (gmt 0)

10+ Year Member



I create the title dynamically by looking at the variables in the URL. It's not a perfect solution, but I think having an appropriate title is important.

For example: index.html?section=widgets&sub=blue

If there is no "sub" variable, the title is "My Site - Widgets". If the sub variable is there, I check it against a list of possible sub-titles: ["Blue Widgets", "Red Widgets"] and just append it: "My Site - Widgets - Blue Widgets"

It's not pretty, but I'm much happier having page titles, especially since I have heard it can improve search engine rankings.

jatar_k

10:18 pm on Jan 10, 2003 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I think that creating the title on the fly from the content on the page would be a little too intensive. You could do it site wide when changes are made and store them in a db. You could write them by hand and store them in a db as well.

Finder's idea is a very nice one, hadn't thought of it. I, personally, would write them all by hand and then store them in a db and then call the proper one for the proper page using an include.

lorax

2:41 am on Jan 11, 2003 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I'm having a hard time imagining what would prevent you from hard coding the titles to begin with - unless you are using a db. If using a db, then follow jatar_k's suggestion and just include the titles in the db (their own field). If not using a db then you've already built the pages yes? So why not add titles at that time? Of have I missed something extremely obvious? :)

keeper

2:55 am on Jan 11, 2003 (gmt 0)

10+ Year Member



I generally have a keyword-rich headline stored in the database, when displaying the content of my page, I request all the content, and for SEO purposes, store the headline text as a php variable and use that variable in the title and <h1> tags on the page.

Seems to work well in the search engines most of the time :)

brotherhood of LAN

3:28 am on Jan 11, 2003 (gmt 0)

WebmasterWorld Administrator brotherhood_of_lan is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I've been re-writing pages to grab info out a db, all the page info is made available by a variable in the filename, i.e. a number.

The number is the primary id for the page, providing title,meta description, page title etc.

IMHO its "lazy" in the fact the titles can be hard coded in certain pages, but for a situation like a "web directory" the dynamic creation of titles if pretty cool, i.e. for > breadcrumb > navigation

paff3

9:23 am on Jan 11, 2003 (gmt 0)

10+ Year Member



ok,my problem is like that:
I have allready made all my pages.
They are built up like that:

<?php
include "1.htm";
?>
<?php
include "2.htm";
?>
<?php
include "3.htm";
?>

title tag is inside 1.htm.
So if i change title,it changes in every page.
Im really stuck.

c3oc3o

10:11 am on Jan 11, 2003 (gmt 0)

10+ Year Member



In 1.htm, where the title tag is, write: <title><?=$title?></title>

And just define that variable before including it:
<?php
$title='My page';
include('1.htm');
?>

paff3

1:08 pm on Jan 11, 2003 (gmt 0)

10+ Year Member



I guess i have to make it your way allthough it takes forever.

aspdaddy

1:41 pm on Jan 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>variable in the title and <h1> tags on the page

I used this a lot, also append it to the end of the meta description.

It is good if you notice a trend in the log files you can update the pages content very quickly i.e xmas/christmas :)

Do you think having H1 & title that match exactly is asking for trouble?

paff3

1:47 pm on Jan 11, 2003 (gmt 0)

10+ Year Member



I know one thing that could solve my problem.Lets say i have title inside body tag.Is there some script that moves title automatically inside head tag.It would really help.Hope you understand what i was trying to say.

andreasfriedrich

4:04 pm on Jan 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Within the body tag you may only use the title attribute. The title element is not allowed.

If the title is hard coded within the body element (though I know of no sensible reason why it should be there) then you could postprocess your output by using output buffering and registering a call back function when starting output buffering [php.net]. A better solution would be to change all your documents. That way the server would not have to do the same work over and over again for each request.

If the title is not hard coded within the body element but the code to get it is currently within your include file that produces the body tag then you should move the code so that it gets executed right at the start of your script as rogerd suggested. c3oc3oīs suggestion is one way to get the title to appear in your first include after the code changes.

If you are willing to share what you do not understand about this approach then I am most certain that somebody here will gladly help you. Just saying I didnt understand sounds more like "I donīt like the advise and canīt be bothered to think about its merits."

Andreas

keeper

12:00 am on Jan 12, 2003 (gmt 0)

10+ Year Member



>>Do you think having H1 & title that match exactly is asking for trouble?

I've never had any trouble before (touching wood now), however, I do concatenate the company name to the title, which makes it a little harder to identify automatically.

For example:
<title>$headline - $companyname</title>
<h1>$headline</h1>

For some of my sites the abstract of the page is also in the database, which makes creating the description tag very easy.

<title>$headline - $companyname</title>
<meta name="description" content="$abstract">

<h1>$headline</h1>
<h2>$abstract</h2>

Leaves with me with training the data entry guys to create keyword rich headlines and abstracts....but thats not as easy as it sounds ;)

<added>paff3, is there anything in your database you can use as a title? otherwise it seems you are left with hardcoding them, or trying to harvest that information from your pages with a view to insert them into the database </added>

aspdaddy

9:30 am on Jan 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Meta keywords dont have much weight but just for good measure :)
<meta keywords=".............." & split(headline,",") & ">"
 

Featured Threads

Hot Threads This Week

Hot Threads This Month