require="metafile"

  • Zealous
  • Guru
  • Guru
  • User avatar
  • Posts: 1244
  • Loc: Sydney

Post 3+ Months Ago

i have been doing a lot of research latly on SEO and different ways to set up a site, so my question is that i would like to put the metadata into a single file and have it required across the site. Now i am sure with a little research i could figure out the snippet but i read a post saying having unique meta on each page will give a better effect then the same meta on all pages.

Is there anyone that could spread more light on the topic?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • WritingBadCode
  • Graduate
  • Graduate
  • User avatar
  • Posts: 214
  • Loc: Sweden

Post 3+ Months Ago

The best suggestion I've seen in this matter is having a "top.php" file that you add to all pages. But Im not sure you want to do this using PHP?

Anyway if you want to do it with PHP this is one way of doing it: First make a database called "metatags". Then add a table to it (looking like this if you want this sample to work):
Code: [ Select ]
CREATE TABLE `metatags`.`metas` (
`description` VARCHAR( 254 ) NOT NULL ,
`keywords` VARCHAR( 254 ) NOT NULL ,
`author` VARCHAR( 254 ) NOT NULL ,
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
) ENGINE = MYISAM ;
  1. CREATE TABLE `metatags`.`metas` (
  2. `description` VARCHAR( 254 ) NOT NULL ,
  3. `keywords` VARCHAR( 254 ) NOT NULL ,
  4. `author` VARCHAR( 254 ) NOT NULL ,
  5. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
  6. ) ENGINE = MYISAM ;


And populate it with something:
Code: [ Select ]
INSERT INTO `metatags`.`metas` (
`description` ,
`keywords` ,
`author` ,
`id`
)
VALUES (
'finaly a cool site', 'best site, coolsite, my site', 'Joe', NULL
);
  1. INSERT INTO `metatags`.`metas` (
  2. `description` ,
  3. `keywords` ,
  4. `author` ,
  5. `id`
  6. )
  7. VALUES (
  8. 'finaly a cool site', 'best site, coolsite, my site', 'Joe', NULL
  9. );


top.php could look something like this:
Code: [ Select ]
<?php
$host= "localhost";
$user= "root";
$password=""; //dbpassword
$db="metatags";
$mytable="metas";
$con = mysql_connect("$host", "$user", "$password") or die(mysql_error());
mysql_select_db("$db");

//basically collects the first (ID) (page?) assuming there is one. Not very dynamic.
$result = mysql_query("SELECT description, keywords, author FROM $mytable WHERE id='1'");

//a very ineffective way to collect the values
while($meta = mysql_fetch_array($result)){
$description = $meta['description'];
$keywords = $meta['keywords'];
$author = $meta['author'];

}
mysql_close($con);
?>


<html>
<head>
<title> some page </title>
<meta name="description" content="<?php echo $description; ?>" />
<meta name="keywords" content="<?php echo $keywords; ?>" />
<meta name="author" content="<?php echo $author; ?>" />
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
</head>
<body>
  1. <?php
  2. $host= "localhost";
  3. $user= "root";
  4. $password=""; //dbpassword
  5. $db="metatags";
  6. $mytable="metas";
  7. $con = mysql_connect("$host", "$user", "$password") or die(mysql_error());
  8. mysql_select_db("$db");
  9. //basically collects the first (ID) (page?) assuming there is one. Not very dynamic.
  10. $result = mysql_query("SELECT description, keywords, author FROM $mytable WHERE id='1'");
  11. //a very ineffective way to collect the values
  12. while($meta = mysql_fetch_array($result)){
  13. $description = $meta['description'];
  14. $keywords = $meta['keywords'];
  15. $author = $meta['author'];
  16. }
  17. mysql_close($con);
  18. ?>
  19. <html>
  20. <head>
  21. <title> some page </title>
  22. <meta name="description" content="<?php echo $description; ?>" />
  23. <meta name="keywords" content="<?php echo $keywords; ?>" />
  24. <meta name="author" content="<?php echo $author; ?>" />
  25. <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  26. </head>
  27. <body>


If you try out this not so cool sample it should produce a half baked html page looking something like this:
Code: [ Select ]
<html>
<head>
<title> some page </title>
<meta name="description" content="finaly a cool site" />
<meta name="keywords" content="best site, coolsite, my site" />
<meta name="author" content="Joe" />
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
</head>
<body>
  1. <html>
  2. <head>
  3. <title> some page </title>
  4. <meta name="description" content="finaly a cool site" />
  5. <meta name="keywords" content="best site, coolsite, my site" />
  6. <meta name="author" content="Joe" />
  7. <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  8. </head>
  9. <body>


where It has collected the meta tags description, keywords and autor from the database. But as you can see you must add a bunch of functionality to make this code useful. :| Hope this was a little helpful. And good luck.
  • Zealous
  • Guru
  • Guru
  • User avatar
  • Posts: 1244
  • Loc: Sydney

Post 3+ Months Ago

wow never figured using SQL for metadata, this is some nice work man i shall test it out and see how it goes.

Thank you sso much for great post :)
  • WritingBadCode
  • Graduate
  • Graduate
  • User avatar
  • Posts: 214
  • Loc: Sweden

Post 3+ Months Ago

Zealous wrote:
wow never figured using SQL for metadata, this is some nice work man i shall test it out and see how it goes.

Thank you sso much for great post :)


No problem, I learned a lot while writing the post too. :D

Cheers!

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 91 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.