SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can one php file (like: group_keywords.php) hold all of my page's keywords together ?

    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.)

  2. #2
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @Knitting_Bunny,

    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:

    <?php

    /*** 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; ?>" />

    <?php
    }
    ?>

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Another way to do it is to have a key (number) hardcoded into the top of each page.
    mypage.php
    PHP Code:
    <?php
    $page 
    23;

    include 
    'header.php';
    include 
    'navigation.php';
    ?>

    // do your static html body content here


    <?php
    include 'footer.php';
    ?>
    Then in header.php maintain an array of values and output them into the header html stream.
    header.php
    PHP Code:
    <?php
    $meta 
    = array(
    => array(
        
    'title'=>'Title for page one',
        
    'keywords'=>'page, one',
        
    'descrip'=>'This is page one',
        ),

    // etc

    23 => array(
        
    'title'=>'Title for page twenty three',
        
    'keywords'=>'page, twenty, three',
        
    'descrip'=>'This is page twenty three',
        ),
    );
    ?>
    <html>
    <title><?=$meta[$page]['title']?></title>
    <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:
    PHP Code:
    <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.

  4. #4
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •