Results 1 to 4 of 4

Thread: [How-To]Control Your Content

  1. #1
    Join Date
    Nov 2006
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default [How-To]Control Your Content

    OK, so some may say this is a waste of time to implement, but I have found it to be EXTREMELY useful in debugging code, quickly adding content menus, etc... So here it is.

    An easy way to keep all of you content under control is to us some simple PHP. The first aspect I will address is, how to keep all of your menus the same.

    Firstly you must have a menu. Now, make a file called menu.php and put that in a directory /php_goddies/ in menu.php you would put all of your HTML that would make up all of your menus.

    menu.php
    PHP Code:
    HTML MENU CODE HERE 
    Now in your index.php and any other page that you want your menu to apear add this code in the place you want your menu to apear.

    index.php
    PHP Code:
    <body>
    <!-- MENU BEGIN -->
        <?php 
        
    include 'http://www.EXAMPLE.com/php_goodies/menu.php' ;
        
    ?>
    <!-- MENU END -->
    For this example I put it right at the beginning of my <body>. Now youu don't have to bother opening every single page and editing links into/out of your menu.

    Now I will show you another simple way to give your pages names very simply.

    So every page has a name that is defined within the <title></title> tags. But if you have another place in your page where you have the page name displayed it can get kind of tiresome to have to go find that part and edit the name. So at the beginning of every page add something like this (variable names may be changed)

    PHP Code:
    <?php 
        $title 
    'Home' //Page Name <title></title>
        
    $name 'Welcome' //name on the page
    ?>
    This code will define each page's name. Now in every page in the <title></title> tag add code similar to this.

    PHP Code:
        <title>Website Name -<?php echo $header?>-</title>
    And then if you have a section where it will say "Welcome" or "About Us" or something you could have code like so,

    PHP Code:
    <b>.::<?php echo $title?>::.</b>
    These are both very simple things to add to your site, and people will probably wonder why I even posted this. But I thought some people within the community would enjoy reading these quick & dirty tips for a more controlled site...

  2. #2
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    133
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default

    very simple, but also informative, well done

  3. #3
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    You can also manage your pages with a variable. Example:
    Code:
    <?php
    $p = $_GET["page"];
    $titles = array("homepage","about","guestbook");
    $pages = array("home.htm","aboutpage.htm","gbook.htm");
    for ($i=0;$i<count($title);$i++) {
        if ($p==$titles[$i]) {
            include $pages[$i];
            }
        }
    ?>
    So if a link was to: yourdomain.com/index.php?page=guestbook
    The output would include "gbook.htm";
    - Mike

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    An associative array is better here:
    Code:
    if($p = @$_GET['page']) {
      $pages = array(
        'homepage' => 'home.htm',
        'about' => 'aboutpage.htm',
        'guestbook' => 'gbook.htm'
      );
    
      if(isset($pages[$p]))
        include($pages[$p]);
    }
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •