Title, keywords with php includes?

Discussion in 'Search Engine Optimization' started by joshtb, Nov 27, 2006.

  1. kkibak

    kkibak Peon

    Messages:
    1,083
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #21
    Hey Josh -- What you're trying to do should be quite easy, but I'm having a hard time understanding exactly how you want it. I get that you have pages named $page.php where $page holds a string with the page file name.

    If my answer here doesn't do what you want, please reply with a clear explanation of exactly how it should work (in just 1 post).

    To access the title variable, assuming it's stored in the url like index.php?page=staff you would just write $page = $_GET['page'];

    $page would then hold the string "staff"

    To make the staff page have a title of "staff" you would then have to delete the old title tag in your code and make a new one like this "<title><?php echo $page; ?></title>
     
    kkibak, Dec 5, 2006 IP
  2. joshtb

    joshtb Active Member

    Messages:
    186
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #22
    I really need a step-by-step on how to fix this. I'm so lost.

    Anyway, let me try to explain. I'm trying to get it so I can change the title, description and keywords on every page via that page. For example, if I want to change staff, I'll edit staff.php. However, at the moment, I can't do that with simple <title> tags because everything is connected to index.php and the title, description and keywords from there are displayed.

    I don't know specifically what I'd want the titles to be, but I'd like to be able to edit them freely, you know? I can't, at the moment.

    I hope this helps.
     
    joshtb, Dec 5, 2006 IP
  3. kkibak

    kkibak Peon

    Messages:
    1,083
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #23
    Okay I think I'm starting to understand the situation..

    How many of these pages are you going to want to name? Is it a few, or is it like thousands or something that you will actually want to change?
     
    kkibak, Dec 5, 2006 IP
  4. joshtb

    joshtb Active Member

    Messages:
    186
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #24
    Nope, thankfully only 20-30 and as I add more (which I will) I will certainly get the title done when they are created. ;)

    I have no problem going through them all.
     
    joshtb, Dec 5, 2006 IP
  5. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #25
    For your site you must be using a database, you'll need to add a description, keywords, and title field to your db. Then you need to add in a code that lets you get those fields on each page and show them to the user.

    ------

    Didn't see your latest reply, this is what i wrote at first.

    I'm not sure how your website works or what it is.. however since its one page it must be created using a database.

    Therefore wherever you are there should be database info regarding that page.

    I generally create unique Title, Description, and Keywords for every page on my site since that works better.. You might as well add in some things to your database for this..

    If your project is too large for this type of concept, or is auto generating content then you'll need to be able to determine a title for the page, which should be whatever a link says which targets this page..

    For example in directories the title should be your category, so "Health Insurance - Directory Name" should be your title, though some prefer to put your directory name first.

    As for description, you should be able to enter a category description into a directory script's database. Otherwise it would be very hard to create an accurate description of the page. As for keywords (maintaining the example of a directory) you could scan the descriptions on your page for the phrases that appear the most often then use those. This would be fairly difficult i guess.

    If you say your websites type (blog,directory etc.) perhaps i can give you better advice.
     
    klown, Dec 5, 2006 IP
  6. joshtb

    joshtb Active Member

    Messages:
    186
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #26
    The only database my site is running off of is the one for the forum. Everything else is done, I suppose you'd call it manually. Nothing is automatic.

    My website is gaming. (not arcade, PC)
     
    joshtb, Dec 5, 2006 IP
  7. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #27
    Well what i generally do is create a single template page then break that into chunks, usually 4. One for headers, one for the top section, one for footer and one for the menu.

    at the top of each page i put some php text like so
    
    $special="";
    $section="aboutus";
    $level="../";
    $title="About Us";
    $metakeywords="About us, about my company, about my company, pmy company services, my company information";
    $metadescription="About my company as a company and information regarding our services, and how we can help you.";
    
    PHP:
    The special allows you to put something into the include to allow a page's heading structure to change, for example some page should be no index, so i have an if then statement in my header.php include that will inject a no follow no index meta if special="bad".

    The section controls the menu system, so it loads a different menu for each section your in, in this example the aboutus menu will have company profile, contact us, our services, and careers links.

    The level is used to control the folder system, this page is not in the main folder its in a second tier folder so all the pictures and links should have a ../ added to them.

    The title is a simple title tag which is injected into your header's title. For my site the header is structured $title - My website name

    obviously the meta description and meta keywords are injected into those slots in the headers.

    Anyhow these variables give you all the info you need to control an entire website's content.

    You should cut a section from your site, say the top menu, and place that into an include labeled "top.php" or something. Then you'll just go to that area on your template and place code like this.

    
    $includeaddress=$level."includes/top.php";
    include ($includeaddress);
    
    PHP:
    anyhow hope this helps a bit..
     
    klown, Dec 5, 2006 IP
  8. joshtb

    joshtb Active Member

    Messages:
    186
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #28
    Couple of things. It's an interesting idea, seems reasonable. What's wrong with just using this:

    
    <?php include("top.php")?>
    Code (markup):
    Are you suggesting the index.php page simply look something like this:

    
    $includeaddress=$level."includes/top.php";
    include ($includeaddress);
    $includeaddress=$level."includes/left.php";
    include ($includeaddress);
    $includeaddress=$level."includes/right.php";
    include ($includeaddress);
    $includeaddress=$level."includes/footer.php";
    include ($includeaddress);
    Code (markup):
     
    joshtb, Dec 5, 2006 IP
  9. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #29
    no you'll likely have unique content on there, mine looks something like this

    
    <?php
    $special="";
    $section="aboutus";
    $level="../";
    $title="About Us";
    $metakeywords="About us, about my company, about my company, pmy company services, my company information";
    $metadescription="About my company as a company and information regarding our services, and how we can help you.";
    
    $includeaddress=$level."includes/header.php";
    include ($includeaddress);
    ?>
    
    <body>
    
    $includeaddress=$level."includes/top.php";
    include ($includeaddress);
    
    <div id="main">
    <?php
    $includeaddress=$level."includes/right.php";
    include ($includeaddress);
    ?>
    
    Page specific content
    
    $includeaddress=$level."includes/footer.php";
    include ($includeaddress);
    
    </div>
    </body>
    </html>
    
    Code (markup):
    very simple, but the php code should fit into the regular page. You should have the body there so you could pop in some css or java code to that page without having to add a bunch to the include.

    I guess you could extend this to a couple more includes to other html parts, anyhow its very basic and short.
     
    klown, Dec 5, 2006 IP
  10. joshtb

    joshtb Active Member

    Messages:
    186
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #30
    Thanks for your help. I'll give it a go tomorrow and post my progress then.
     
    joshtb, Dec 5, 2006 IP
  11. kkibak

    kkibak Peon

    Messages:
    1,083
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #31
    Just because I think klown has a different understanding of the problem than mine, and I'm not sure who is interpreting it right, here's the way I would do it (this should replace the current <title> area in your head tags:

    
    
    <?php
    
    $page = $_GET['page'];
    
    if(!(isset($page)))
      echo "<title>My Generic Title</title>";
    else {
      switch ($page) {
      case "aboutus":
         echo "<title>About Us</title>";
         break;
      case "contact":
         echo "<title>Contact</title>";
         break;
      case "elephants":
         echo "<title>Elephants</title>";
         break;
      }
    }
    
    ?> 
    
    Code (markup):
    Then, for each page you want to add a custom title to, you take the page name (whatever comes after index.php?page=) and add it to the code before the second to last }. For example, if you wanted to add a custom title for index.php?page=newpage you would modify the code to look like this:

    
    
    <?php
    
    $page = $_GET['page'];
    
    if(!(isset($page)))
      echo "<title>My Generic Title</title>";
    else {
      switch ($page) {
      case "aboutus":
         echo "<title>About Us</title>";
         break;
      case "contact":
         echo "<title>Contact</title>";
         break;
      case "elephants":
         echo "<title>Elephants</title>";
         break;
    [B]  case "newpage":
         echo "<title>New Page Title</title>";
         break; [/B]
      }
    }
    
    ?> 
    
    Code (markup):
    This isn't the most beautiful way to handle titles, but it will work fine if you're not adding TONs of them.

    To keep the code clean you could even store all of that in a special file called "pagetitles.php" or something and then just add include 'pagetitles.php'; to the index.php file.

    Hope this helps, and I hope I understood the problem correctly :D
     
    kkibak, Dec 5, 2006 IP
  12. joshtb

    joshtb Active Member

    Messages:
    186
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #32
    I think you got it! Thanks so much.

    How's about keywords/description?
     
    joshtb, Dec 5, 2006 IP
  13. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #33
    You must be dealing with a database of some kind if this solution works for you. You should generate keywords and descriptions from your database.
     
    klown, Dec 5, 2006 IP
    kkibak likes this.
  14. kkibak

    kkibak Peon

    Messages:
    1,083
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #34
    Like klown said this stuff is best handled with a database, but if you can't go that route for some reason, here's how you'd add descriptions (new code in bold, I only changed the first one as an example, you do the exact same thing to change the others):

    
    <?php
    
    $page = $_GET['page'];
    
    if(!(isset($page)))
      echo "<title>My Generic Title</title>";
    else {
      switch ($page) {
      case "aboutus":
         echo "<title>About Us</title>\n";
    [B]     echo "<meta name=\"keywords\" content=\"about us keywords here\">\n";
         echo "<meta name=\"description\" content=\"about us description here\">\n";[/B]
         break;
      case "contact":
         echo "<title>Contact</title>";
         break;
      case "elephants":
         echo "<title>Elephants</title>";
         break;
      }
    }
    
    ?>
    
    Code (markup):
    the \n is just to add a new line so that your html is more readable if you view source later.. not entirely necessary
     
    kkibak, Dec 5, 2006 IP
  15. joshtb

    joshtb Active Member

    Messages:
    186
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #35
    I tried doing this:

    <?php
    
    $page = $_GET['page'];
    
    if(!(isset($page)))
      echo "<title>TwistedPortal.com :: Counter-Strike | Condition Zero | Source | Steam</title>";
      echo "<meta name=\"keywords\" content=\"test\">";
      echo "<meta name=\"description\" content=\"test1\">";
    else {
      switch ($page) {
      case "partners":
         echo "<title>TwistedPortal.com - Partners</title>";
         break;
      case "servers":
         echo "<title>TwistedPortal.com - Servers :: Counter-Strike | Condition Zero | Source | Gameservers</title>";
         echo "<meta name=\"keywords\" content=\"servers\">\n";
         echo "<meta name=\"description\" content=\"servers\">\n";
         break;
      }
    }
    
    ?>
    
    Code (markup):
    So that the index page would have its own keywords too, but I get an error: Parse error: syntax error, unexpected T_ELSE in /home/joshb/public_html/index.php on line 11
     
    joshtb, Dec 6, 2006 IP
  16. joshtb

    joshtb Active Member

    Messages:
    186
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #36
    Also, I was curious: http://www.twistedportal.com/sitemap.html

    Is that a bad sitemap? I looked around on Google on how to create one and this site had an automated form to do it for me. Looks weird to me as I only have about thirty pages.
     
    joshtb, Dec 6, 2006 IP
  17. joshtb

    joshtb Active Member

    Messages:
    186
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #37
    Bumping...

    Sorry again.
     
    joshtb, Dec 7, 2006 IP