View Full Version : 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
Jamesy
09-07-2009, 12:39 PM
on the index.html you would make the link a new class, eg
<a href="/" class="active">Home</a>
and then for styling you might have:
a {
color:#000;
}
a:hover {
color:green;
}
a.active{
color:red;
}
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.
Blinger1
10-07-2009, 09:52 AM
You could do something like this
<?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:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Webpage</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
and the footer:
</body>
</html>
Dentafrice
10-07-2009, 03:56 PM
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
/* 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); ?>
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
/* 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!
Dentafrice
11-07-2009, 08:59 PM
No problem :)
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 (http://127.0.0.1/Site%201/index.php) About (http://127.0.0.1/Site%201/index.php?page=about) Stuff (http://127.0.0.1/Site%201/index.php?page=stuff)
Warning: include() [function.include (http://127.0.0.1/Site%201/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)
Blinger1
12-07-2009, 12:26 PM
just by looking at it, it looks like you need brackets around the realpath function?
Jam-ez
12-07-2009, 01:30 PM
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 (http://127.0.0.1/Site%201/index.php) About (http://127.0.0.1/Site%201/index.php?page=about) Stuff (http://127.0.0.1/Site%201/index.php?page=stuff)
Warning: include() [function.include (http://127.0.0.1/Site%201/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
/* 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:
<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.
Ok thanks :)
All i get now is:
Notice: Undefined index: page in C:\Program Files\EasyPHP 3.0\www\Site 1\index.php on line 15
any idea?
line 15 is:
$page_name = $_GET["page"];
Jam-ez
12-07-2009, 02:04 PM
What is your directory structure, and is the file which contains the code named index.php?
yes. it's name index.php.
the structure is
public_html/index.php
public_html/pages/page.php
Dentafrice
12-07-2009, 04:58 PM
It's a notice, it's telling you that you didn't define $page first.
At the top of your page put:
error_reporting(E_ALL ^ E_NOTICE);
Should do it.
Thanks all. :)
Works fine now thanks caleb +Rep to all
Ok. hit an error. it's not liking it when the link has been visited.
when the link has been visited, the class seems to knock out.
so it stays unactive even when on the page, once link has been visited.
Flisker
13-07-2009, 12:45 AM
i believe the style for that is
a:visited {
color: #000;
}
i believe the style for that is
a:visited {
color: #000;
}
yes, it is.
but when the link has been visited, no matter what page you're on, none of them change class to "active" anymore.
Flisker
13-07-2009, 09:42 AM
yes, it is.
but when the link has been visited, no matter what page you're on, none of them change class to "active" anymore.
No because they are already visited so just make the colour the same on both
no chris, you're not understanding me.
i've formatted the visited and non visited the same.
that's not my problem.
my problem is, once a link has been visited, and the person returns to the page, none of them turn active when they should be.
Jam-ez
13-07-2009, 05:21 PM
no chris, you're not understanding me.
i've formatted the visited and non visited the same.
that's not my problem.
my problem is, once a link has been visited, and the person returns to the page, none of them turn active when they should be.
Only home should be active on return to the page, due to the fact that the url triggers the changing of the page? Or do you mean on return to the page, when you click a button nothing has an effect? If so, copy the url you're getting on return to the page after clicking al ink that doesn't turn active, and explain in more detail what you mean...
Basically. Once I've visited say... "index.php?page=about", the first time I visit that page, the button will turn active. After I've visited it that once, it'll stop changing to active if you get me?
Jam-ez
14-07-2009, 02:28 PM
Basically. Once I've visited say... "index.php?page=about", the first time I visit that page, the button will turn active. After I've visited it that once, it'll stop changing to active if you get me?
In your css, you'd need to change (I'm guessing) - if you are using <a href...></a>,
a:visited {
}
Just post back here if you're still struggling - try google as well! :)
This is so difficult to explain.
Right.
Let's say.
You load index.php for the first time
Here's the links:
hi i'm active
hi im unactive
hi im unactive 2
so now you click on i'm unactive 2
This is so difficult to explain.
Right.
Let's say.
You load index.php for the first time
Here's the links:
hi i'm active
hi im unactive
hi im unactive 2
So now that's active.
Then say I want to go back to the first link.
I click.
It loads.
It's now:
This is so difficult to explain.
Right.
Let's say.
You load index.php for the first time
Here's the links:
hi i'm active
hi im unactive
hi im unactive 2
Getting me?
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.