Skip to content

What's a good way to set your title for each page?

Currently I use a system that is like header, index, footer. The index imports the header at top and footer at the bottom and the header has all the including stuff needed for each page and as well as the <head></head> stuff. The only problem is that I have not really a good idea how I should be able to make something like a forum that has the title of the thread as a title on the current page (like: My site - title of thread).

So how would you do it?

Basic mockup of my current way:

header:

php including and variables created

<html> <head> <title>yay</title> *linking in stylesheets, java etc.* </head> <body>

adding stuff that should be on every page

index:

include header

alot of code

include footer

footer:

my footer

</body> </html>
1 points2 comments
Open on Reddit
About this post
Posted
Archived
Score
1 · 100% up
Kind
Text
ID
cuugg

Author

16
posts
162
comments
7
media
View profile

2 comments

Header should be just your html and stuff, so set a var in your main file (eg, index.php).

index.php:

<?php
$page_title = 'My page';
//or hit the db and get the post/topic/whatever title
include('header.php');

//rest of your code
?>

header.php

<?php
if($page_title == '')
    $page_title = 'My Site';
?>
<html>
<head>
<title><?php echo $page_title;?></title>
<!--etc...-->
1 points

In your header, check the value of the postId or whatever you call it in your query string. Then make a trip to the database, retrieve the subject of that post, and drop it in the title tag.

0 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.