Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP links include with current page :)
Old 09-10-2008, 10:36 AM PHP links include with current page :)
Defies a Status

Posts: 2,071
Name: carl
Location: UK
Trades: 0
I did it, had to sift through loads of stuff and modify an example script but I can now put links on the page and the current page has a class o current.

Before I go patting myself on the back to much though I thought I would post it here and ask if theres a better way to do it - heres what i've done

Give the pages a name (at top of page)
PHP Code:
<?php $thisPage="LifeCover"?>
link to the include page where I want the links to go

PHP Code:
<?php include("assets/insurance-links.php"); ?>
Then on the includes page I put

PHP Code:
<ul>
   <li><a href="insurance-mpp.html"
   <?php if ($thisPage=="MPPI") echo " class=\"rsbcurrent\""?>>Mortgage Payment Protection &amp; ASU</a></li>
   <li><a href="insurance-lifecover.html"
   <?php if ($thisPage=="LifeCover") echo " class=\"rsbcurrent\""?>>Life Cover - why bother?</a></li>
</ul>
It is on these pages

http://www.bakerfinancial.co.uk/insu...lifecover.html
(the insurance links bottom right)

I only used these links until I check its the right way to do it.

Please let me know if there is a cleaner or better way of doing it...1st ever php thing I done myself ,
its not the size that counts its how ya use it
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Last edited by bakerc; 09-10-2008 at 10:38 AM..
bakerc is offline
Reply With Quote
View Public Profile Visit bakerc's homepage!
 
 
Register now for full access!
Old 09-10-2008, 11:00 AM Re: PHP links include with current page :)
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Here's a simple example of how I do this (sometimes I also do it in JavaScript, also, which is super-simple, since you can match the window location against the href of the link):

Let's say this is index.php:
PHP Code:
<?php page="index";?>
<html>
<head>
<title>Home</title>
<!--meta, etc.-->
<?php include "header.php";?>
<!--document continues here-->
Now, let's say this is header.php:
PHP Code:
<link href="master.css" rel="stylesheet" type="text/css" />
<!--Links to scripts, etc-->
</head>

<body class="<?php echo $page?>"><!--note class on body is the same as the page name.  This is handled from an included file so that this code doesn't have to be repeated constantly.  This is nice because it gives us the opportunity to easily identify each page in the CSS document-->

<div id="wrapper"><!--each <li> has a unique id that matches the page name-->
<ul id="navigation">
<li id="index"><a href="/">Home</a></li>
<li id="about"><a href="/about.php">About</a></li>
<li id="contact"><a href="/contact.php">Contact</a></li>
</ul>
Now, let's say this is the CSS file that we have linked to, called master.css:
CSS
Code:
.index #index a, .about #about a, .contact #contact a {
background: #fff !important; /*or whatever you need as an active style.  This is tagged with !important so that it covers the :visited state, but if you wish to have seperate styles for :visited links, you will need to specify this and drop the !important*/
}
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.

Last edited by wayfarer07; 09-10-2008 at 11:10 AM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 09-10-2008, 11:12 AM Re: PHP links include with current page :)
Defies a Status

Posts: 2,071
Name: carl
Location: UK
Trades: 0
Hi Abel,

The included is just for links that I have dotted around the page. I dont want to change the style for the page or anything.

I was going to use JS, i rekon it would have been a little easier (I seem to "get" JS a bit better than PHP) but I wanted to use php as I didn't want the way the links look to be altered if the user has JS turned off.

The way I done it the only file I would have to update is the links file (/insurance-links.php or mortgage-links.php) as I add more pages. Its only 1 css class that can site in the main css file.

It looks like you make up all your page with includes, I currenlty use a template I made but I will be doing everything with includes eventually but not yet, when I do that I will be re-doing the site completely but for now I just want to make adding new pages easier.

Or have I missed something?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Last edited by bakerc; 09-10-2008 at 11:15 AM..
bakerc is offline
Reply With Quote
View Public Profile Visit bakerc's homepage!
 
Old 09-10-2008, 11:25 AM Re: PHP links include with current page :)
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Well, there are plenty of ways to do this. Personally, I just don't like embedding if{} statements in all of my links, and would rather just echo one class onto the body and place ids on all of the links so that I can control everything from the CSS file.

You're right in observing that all of the pages would have to have the includes. The sites I build are always structured something like this:
PHP Code:
<?php $page "whatever";
include 
"inc/init/php"//classes, functions, connection to database, document type, opening <html> and <head> tags?>
<!--title and meta-->
<?php include "inc/head.php"// links to styles, scripts, initial logic for pages, closing </head> tag, opening <body> tag, top of webpage (shared information), usually includes navigation?>
<div id="wrapper">
<!--site structure, dynamic data, sometimes other includes-->
</div>
<?php include "inc/footer.php"//bottom of site (shared data), closing </body> tag ?>
There is absolutely nothing wrong with the way you're doing it.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.

Last edited by wayfarer07; 09-10-2008 at 11:28 AM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 09-10-2008, 11:37 AM Re: PHP links include with current page :)
Defies a Status

Posts: 2,071
Name: carl
Location: UK
Trades: 0
Hi Abel

Thanks for the info - I will have my site done that way eventually but changing thing over slowley to make sure I know the ins and outs of what I am doing.

One quick question, if you set a class for the page and then use ID's for the links, is that not pretty much the same as setting the links a class? as their style will still be controled by the stylesheet? and would have their own class (I have differenet links with different styles)
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Last edited by bakerc; 09-10-2008 at 11:40 AM..
bakerc is offline
Reply With Quote
View Public Profile Visit bakerc's homepage!
 
Old 09-10-2008, 12:24 PM Re: PHP links include with current page :)
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Well you could put an id for the body and classes for the links, if you like. The idea is that they are named the same thing, so that it is easy to remember when targeting each one in the stylesheet, plus the fact that you can only repeat an ID element once per page.

I've been giving this subject a bit more thought, and posted a quick tip about how to do this with javascript: Active Links With JavaScript (just to add to the confusion )
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 09-10-2008, 12:27 PM Re: PHP links include with current page :)
Defies a Status

Posts: 2,071
Name: carl
Location: UK
Trades: 0
Cheers for the link
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
bakerc is offline
Reply With Quote
View Public Profile Visit bakerc's homepage!
 
Reply     « Reply to PHP links include with current page :)
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.60310 seconds with 12 queries