Page 1 of 3 123 LastLast
Results 1 to 10 of 24
  1. #1
    Join Date
    May 2005
    Location
    united kingdom
    Posts
    8,084
    Tokens
    595

    Latest Awards:

    Default how would I... (Links in HTML)

    ok.
    so basically.
    i want to make a rollover.
    but at the same time, when whatever page is clicked and on the right i want it to be selected.

    so like this:
    Home when viewing the page "about.html"
    but when on "index.html" I want it to be say... Home buttt... then when I rollover it... I want it to be Home

    Basically, so I can have rollovers and at the same time they know what page they are viewing. Or, if that's not possible, scrap the rollover, just so that they know what the page is they are viewing. an example would be this:
    http://keypublishing.co.uk/

    how it's formatted differently when they are viewing that page.
    however, i will be using images
    Last edited by myke; 09-07-2009 at 12:27 PM.

    drink up this bottle of yeah
    and P A I N T your body on me


  2. #2
    Join Date
    Nov 2006
    Location
    Narrich
    Posts
    5,687
    Tokens
    0
    Habbo
    Jamesy...

    Latest Awards:

    Default

    on the index.html you would make the link a new class, eg

    Code:
    <a href="/" class="active">Home</a>
    and then for styling you might have:

    Code:
    a {
    color:#000;
    }
    
    a:hover {
    color:green;
    }
    
    a.active{
    color:red;
    }
    Ex-janitor. Might pop in from time to time, otherwise you can grab all my information from http://jamesy.me.uk/

  3. #3
    Join Date
    May 2005
    Location
    united kingdom
    Posts
    8,084
    Tokens
    595

    Latest Awards:

    Default

    Is it possible for this to work with php includes? because I don't plan on making a complete new page each time e.g. about.html won't contain all the body information, just the information needed in the content box.

    drink up this bottle of yeah
    and P A I N T your body on me


  4. #4
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    7,554
    Tokens
    0

    Latest Awards:

    Default

    You could do something like this

    PHP Code:
    <?php
    include("header.php");
    ?>
    this is the middle of the code, blah blah blah!
    <?php
    include("footer.php");
    ?>
    obviously it would not be the fastest code around

    edit:

    and for the header.php you could have something like this:



    and the footer:
    Last edited by Blinger1; 10-07-2009 at 09:54 AM.

  5. #5
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    How are you PHP includes working? Are you getting a variable out of the filename (index.php?page=about) or something?

    If so.. just something..

    PHP Code:
    <?php
    /* Sets up the page folder */
    $page_folder realpath("pages") . "/";

    /* Get the page name from the URL.  index.php?page=page_name */
    $page_name $_GET["page"];
    $page_name = ($page_name == '') ? 'home' $page_name;

    $page $page_folder "{$page_name}.php";

    /* Check to see if the file exists, if it doesn't.. do a 404 page. */
    if(!file_exists($page)) {
        
    $page $page_folder "404.php";
    }
    ?>

    <!-- now for the header -->

    <a href="index.php" <?php if($page_name == "" || $page_name == "home") { echo 'class="active"'; } ?>>Home</a>
    <a href="index.php?page=about" <?php if($page_name == "about") { echo 'class="active"'; } ?>>About</a>
    <a href="index.php?page=stuff" <?php if($page_name == "stuff") { echo 'class="active"'; } ?>>Stuff</a>

    <!-- now include blabla -->

    <?php include realpath($page); ?>

  6. #6
    Join Date
    May 2005
    Location
    united kingdom
    Posts
    8,084
    Tokens
    595

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    How are you PHP includes working? Are you getting a variable out of the filename (index.php?page=about) or something?

    If so.. just something..

    PHP Code:
    <?php
    /* Sets up the page folder */
    $page_folder realpath("pages") . "/";

    /* Get the page name from the URL.  index.php?page=page_name */
    $page_name $_GET["page"];
    $page_name = ($page_name == '') ? 'home' $page_name;

    $page $page_folder "{$page_name}.php";

    /* Check to see if the file exists, if it doesn't.. do a 404 page. */
    if(!file_exists($page)) {
        
    $page $page_folder "404.php";
    }
    ?>

    <!-- now for the header -->

    <a href="index.php" <?php if($page_name == "" || $page_name == "home") { echo 'class="active"'; } ?>>Home</a>
    <a href="index.php?page=about" <?php if($page_name == "about") { echo 'class="active"'; } ?>>About</a>
    <a href="index.php?page=stuff" <?php if($page_name == "stuff") { echo 'class="active"'; } ?>>Stuff</a>

    <!-- now include blabla -->

    <?php include realpath($page); ?>
    Exactly what I wanted - thanks!

    drink up this bottle of yeah
    and P A I N T your body on me


  7. #7
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    No problem

  8. #8
    Join Date
    May 2005
    Location
    united kingdom
    Posts
    8,084
    Tokens
    595

    Latest Awards:

    Default

    I just put this code into its own document to test it and mess around with it to see what I can make from it.

    I got this error:


    Notice: Undefined index: page in C:\Program Files\EasyPHP 3.0\www\Site 1\index.php on line 15
    Home About Stuff
    Warning: include() [function.include]: Failed opening '' for inclusion (include_path='.;C:/Program Files/EasyPHP 3.0\php\includes') in C:\Program Files\EasyPHP 3.0\www\Site 1\index.php on line 34


    using just the code you posted ... any idea? lol.

    (aye, nooby php kid here)
    Last edited by myke; 12-07-2009 at 12:26 PM.

    drink up this bottle of yeah
    and P A I N T your body on me


  9. #9
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    7,554
    Tokens
    0

    Latest Awards:

    Default

    just by looking at it, it looks like you need brackets around the realpath function?

  10. #10

    Default

    Quote Originally Posted by Myke View Post
    I just put this code into its own document to test it and mess around with it to see what I can make from it.

    I got this error:


    Notice: Undefined index: page in C:\Program Files\EasyPHP 3.0\www\Site 1\index.php on line 15
    Home About Stuff
    Warning: include() [function.include]: Failed opening '' for inclusion (include_path='.;C:/Program Files/EasyPHP 3.0\php\includes') in C:\Program Files\EasyPHP 3.0\www\Site 1\index.php on line 34


    using just the code you posted ... any idea? lol.

    (aye, nooby php kid here)
    Just tested, the code Dentafrice gave you does work. I just added some line breaks.
    PHP Code:
    <?php
    /* Sets up the page folder */
    $page_folder realpath("pages") . "/";

    /* Get the page name from the URL.  index.php?page=page_name */
    $page_name $_GET["page"];
    $page_name = ($page_name == '') ? 'home' $page_name;

    $page $page_folder "{$page_name}.php";

    /* Check to see if the file exists, if it doesn't.. do a 404 page. */
    if(!file_exists($page)) {
        
    $page $page_folder "404.php";
    }
    ?>

    <!-- now for the header -->

    <a href="index.php" <?php if($page_name == "" || $page_name == "home") { echo 'class="active"'; } ?>>Home</a>
    <a href="index.php?page=about" <?php if($page_name == "about") { echo 'class="active"'; } ?>>About</a>
    <a href="index.php?page=stuff" <?php if($page_name == "stuff") { echo 'class="active"'; } ?>>Stuff</a>

    <!-- now include blabla -->

    <?php echo '<br/ ><br />'; include realpath($page); ?>
    All you have to do, is create a directory named "pages" inside the folder where this code is placed. Then create pages "home.php", "about.php", and "stuff.php" - these can be changed by editing these lines:
    Code:
    <a href="index.php" <?php if($page_name == "" || $page_name == "home") { echo 'class="active"'; } ?>>Home</a>
    <a href="index.php?page=about" <?php if($page_name == "about") { echo 'class="active"'; } ?>>About</a>
    <a href="index.php?page=stuff" <?php if($page_name == "stuff") { echo 'class="active"'; } ?>>Stuff</a>
    As you can see, simply change ?page=stuff, and $page_name, instead. If you have any questions, feel free to PM me.

Page 1 of 3 123 LastLast

Posting Permissions

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