Jump to content

Page Titles and Meta information with includes


adipalmer123

Recommended Posts

Hi all

 

Recently designed a site using includes, but only realised when I'd almost finished the project that because the (e.g.) include("includes/header.html"); had the <head> information (titles, meta description, etc) every single page included the same information (by the way hope this makes sense)

 

A way I thought of getting around this was to store each pages title and meta description in a database or in for example or maybe in a variables.php file. But I'm not sure whether this is the best way.

 

I'm not a PHP expert so simple explainations would be very much appriciated.

 

Look forward to hearing from you all.

 

Adi

hmm I think I understand what you're saying..

try doing this:

 

$title="this is my title";

$meta_desc="my description";

$meta_key="my, key, words";

include('header.php');

 

then inside header.php place $title $meta_desc and $meta_key in meta tags and title tags

in every page use this

$title="this is my title";

$meta_desc="my description";

$meta_key="my, key, words";

include('header.php');

 

change what is in them for each page. say its a game page and you want the title to be the game, do this:

 

$query=mysql_query("QUERY HERE");

$row=mysql_fetch_array($query);

$title="$row[title]";

$meta_desc="$row[desc]";

$meta_key="games, free, cool, $row[title]";

include('header.php');

I understand the first part, but excuse my beginner mentallity :- could you explain the second part a little more?

 

How does the below work?

$query=mysql_query("QUERY HERE");

$row=mysql_fetch_array($query);

$title="$row[title]";

$meta_desc="$row[desc]";

$meta_key="games, free, cool, $row[title]";

include('header.php');

 

Cheers

Well make up a query say

 

$query = mysql_query("SELECT * FROM `games` WHERE id='$_GET[id]'");

 

so now this is what you want to extract and show so you do the following

 

$row = mysql_fetch_array($query);

 

now you can show any field you want.

 

$row['title'] will show the title of the game. so then you can add the title of the game to the title tags.

 

Understand?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.