EDIT: I'm refering to META TAG keywords, titles, and descriptions.
Is this possible with PHP or any other way?
- I am a rookie users of PHP.
- My site is small and static (but I have plan for more sites)
- I know simple includes ( like for navigation and footer.)
- I can put in dates etc. with PHP.
Opening each page separately to edit titles, keywords, and description is getting tedious.
Each page has unique keywords, titles, and descriptions. They're not all the same.
Can one php file (like: group_keywords.php) hold all of my page's keywords together in one place?
If yes, could it also hold descriptions and title in that same group file? (like: group_KeyDesTitle.php)?
How would I then call it on the individual pages? PageOne, PageTwo, and PageThree would all be calling to group_keywords.php - something must tell it what to seek on that page, right?
If not through PHP, is there some other way to do this?
Thanks in advance.
(I'm only smart enough to dream up something screwy, then promptly mess it up, when it comes to code. It's safer for the world when I knit instead.)
IF I MAY UNDERSTAND YOU, YOU WANT TO CREAT A FUNCTION YOU CAN CALL ON EVERY PAGE OF YOU WEBSITE TO RETURN THE META TAG?
IF YOUR ANSWER IS YES, THEN TRY THIS:
/*** YOU CAN COPY THIS CODE TO YOUR PHP FILE group_KeyDesTitle.php FOLLOW THE STEPS BELOW:
1) Save the group_KeyDesTitle.php in the same directory with the PHP files you wish to add the keywords, description and title
2) include the group_KeyDesTitle.php.
3) Call the function metaKeyword() and pass the arguments
BY: OLIYIDE Oluwafemi John
function metaKeyword($title, $metaName , $metaNameDescription , $metaKeyword , $metaKeyDescription )
<title><?php echo $title; ?></title>
<meta name="<?php echo $metaKeyword; ?>" content="<?php echo $metaKeyDescription; ?>" />
<meta name="<?php echo $metaName; ?>" content="<?php echo $metaDescription; ?>" />
Another way to do it is to have a key (number) hardcoded into the top of each page.
$page = 23;
// do your static html body content here
Then in header.php maintain an array of values and output them into the header html stream.
$meta = array(
1 => array(
'title'=>'Title for page one',
'descrip'=>'This is page one',
23 => array(
'title'=>'Title for page twenty three',
'keywords'=>'page, twenty, three',
'descrip'=>'This is page twenty three',
<meta name=keywords value='<?=$meta[$page]['keywords']?>' />
<meta name=keywords value='<?=$meta[$page]['descrip']?>' />
I've left lots out here, like checking if key 23 actually exists prior to trying to echo it. It also presumes you have PHP short tags ON, otherwise you'd have to do this:
<title><?php echo $meta[$page]['title']; ?></title>
You can then go on expanding this idea, put the header code into a function, output some default values if the $page key is missing, you could store the arrays as an ini file -- eventually you may find it easier to put the values in a database however.
Keywords might benefit from being held in a db, if you wanted to sort your pages by keyword, for example.
Thank you both for helping. I'm going to test out what you've each suggested and see if I understand it correctly. I'll post back and let you know how it works out.
This topic is now closed. New replies are no longer allowed.