a webmaster learning community
     Home    Register     Search      Help      Login    
FrontPage Alternative
Sponsors

Hosting from $3.99 per month!

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions. dd

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

 

PHP includes problem - any ideas

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> General Web Development >> PHP includes problem - any ideas
Page: [1]
 
womble

 

Posts: 5721
Joined: 3/14/2005
From: Living on the edge
Status: offline

 
PHP includes problem - any ideas - 1/15/2007 16:44:37   
I've used the following method to include a menu and highlight the current page on a previous web project without any problems, but on this project I can't get it to work. On the current page an id of "active" should get added to the <li> tag, and a "current" class to the <a> tag. The menu gets included, but the current page doesn't highlight - any ideas?

Menu section on the current page:
      <!-- NAVIGATION -->
      <div class="navigation">
        <div class="curved_corner"></div>
        <p class="navtitle">What's here?</p>
 <!-- start navigation include -->
		<?php include("includes/menu_include.php"); ?>
<!-- end navigation include -->


Menu_include.php:
<?php
	$menu = file_get_contents("menu.html");
	$menu = preg_replace("|<li id=\"active\"><a class=\"current\" href=\"" . basename($_SERVER['PHP_SELF']) . "\">(.*)</[^>]+></li>|U", "</a>", $menu);
	echo $menu;
?>


The menu.html file:
 		<ul class="navlist">
			<li><a href="index.php">Home</a></li>
			<li><a href="designs.php">Designs</a>
				<ul class="subnavlist">
					<li><a href="design1.php">Design 1</a></li>
					<li><a href="design2.php">Design 2</a></li>
					<li><a href="design3.php">Design 3</a></li>
				</ul>
			</li>
			<li><a href="#">Graphics</a></li>
			<li><a href="about.php">About</a></li>
			<li><a href="links.php">Links</a></li>
			<li><a href="contact.php">Contact Me</a></li>




_____________________________

~~ "A cruel god ain't no god at all" ~~
~~ Erase hate. Practice love. ~~
:)
jaybee

 

Posts: 14207
Joined: 10/7/2003
From: Berkshire, UK
Status: offline

 
RE: PHP includes problem - any ideas - 1/15/2007 17:37:30   

<?php include("includes/menu_include.php"); ?>


Menu_include.php:

?

_____________________________

If it ain't broke..... fix it until it is.
:)

:)
GAWDS
Now where did I put that Doctype?

(in reply to womble)
womble

 

Posts: 5721
Joined: 3/14/2005
From: Living on the edge
Status: offline

 
RE: PHP includes problem - any ideas - 1/15/2007 18:17:25   
Oops! Nope, I just capitalised on the post. All my filenames are lowercase.

_____________________________

~~ "A cruel god ain't no god at all" ~~
~~ Erase hate. Practice love. ~~
:)

(in reply to jaybee)
jaybee

 

Posts: 14207
Joined: 10/7/2003
From: Berkshire, UK
Status: offline

 
RE: PHP includes problem - any ideas - 1/15/2007 18:38:38   
Just a thought, without really putting the poor old brain to work, you have a dummy link

<li><a href="#">Graphics</a></li>

I've had problems in the past when I've used dummy links.

Other than that, if the code is identical, is it on the same host?

_____________________________

If it ain't broke..... fix it until it is.
:)

:)
GAWDS
Now where did I put that Doctype?

(in reply to womble)
womble

 

Posts: 5721
Joined: 3/14/2005
From: Living on the edge
Status: offline

 
RE: PHP includes problem - any ideas - 1/15/2007 19:02:31   
Ummmm...

/scrabbles about on PDA looking for domain account details...

...yup. Same hosts.

I just realised looking at it again though that I seem to have messed up somewhere in copying and pasting and then editing. The list items are slightly different on the two menus. On the original it was this line:

$menu = preg_replace("|<li><a href=\"" . basename($_SERVER['PHP_SELF']) . "\">(.*)</[^>]+></li>|U", "<li class=\"current\"><span class=\"background\">$1</span></li>", $menu);


...which is somewhat different from what I'd got. I've now changed it to this:

	<?php
	$menu = file_get_contents("menu.html");
	$menu = preg_replace("|<li><a href=\"" . basename($_SERVER['PHP_SELF']) . "\">(.*)</[^>]+></li>|U", "<li id=\"active\"><a class=\"current\">$1</a></li>", $menu);
	echo $menu;						
?>


Still not playing though. It's including the menu, but not highlighting the current page. Obviously there's something wrong with the syntax somewhere, but I can't figure out where. :)

Maybe it'll all make more sense after a good night's sleep....

_____________________________

~~ "A cruel god ain't no god at all" ~~
~~ Erase hate. Practice love. ~~
:)

(in reply to jaybee)
womble

 

Posts: 5721
Joined: 3/14/2005
From: Living on the edge
Status: offline

 
RE: PHP includes problem - any ideas - 1/15/2007 19:52:40   
:) Yay! Sussed it!

First I realised that I didn't need the id and the class, just the id on the <li>.
Then I realised that I hadn't got "basename($_SERVER['PHP_SELF']" in the <a> tag that was replacing the orginal - put that in.
Right stuff showing up on 'view source', but still not lightly up, which meant I'd also got a problem with the CSS....realised I'd got not got the 'a' on the style...duh!

So, finished code incase it's any use to anyone...

html...
      <!-- NAVIGATION -->
      <div class="navigation">
        <div class="curved_corner"></div>
        <p class="navtitle">What's here?</p>
 <!-- start navigation include -->
		<?php include("includes/menu_include.php"); ?>
 <!-- end navigation include -->


CSS...
.navlist { width: 199px; color: #467aa7; background-color: #F2F3F5; border-right: 1px solid #c8c8c8; border-bottom: 1px solid #c8c8c8; font: 12px verdana,sans-serif; }
.navlist li { list-style: none; }
.navlist a { color: #467aa7; text-decoration: none; display: block; border-left: 1em solid #c8c8c8; border-top: 1px solid #c8c8c8; padding: 4px 8px; }
.navlist a:hover { border-color: #606B8B; }
ul.navlist li#current a { border-color: #606B8B; }
.subnavlist li a { border: 0; border-left: 0.8em solid #c8c8c8; padding: 3px 4px; margin-left: 20px; }


Menu include file (menu.html)
<ul class="navlist">
			<li><a href="index.php">Home</a></li>
			<li><a href="designs.php">Designs</a>
				<ul class="subnavlist">
					<li><a href="design1.php">Design 1</a></li>
					<li><a href="design2.php">Design 2</a></li>
					<li><a href="design3.php">Design 3</a></li>
				</ul>
			</li>
			<li><a href="graphics.php">Graphics</a></li>
			<li><a href="about.php">About</a></li>
			<li><a href="links.php">Links</a></li>
			<li><a href="contact.php">Contact Me</a></li>


And the menu_include.php file that does the clever replacing to add in the id on the <li>...
<?php
     $menu = file_get_contents("menu.html");
     $menu = preg_replace("|<li><a href=\"" . basename($_SERVER['PHP_SELF']) . "\">(.*)</[^>]+></li>|U", "<li id=\"current\"><a href=\"" . basename($_SERVER['PHP_SELF']) . "\">$1</a></li>", $menu);
     echo $menu;
     ?>	


The only problem is, I don't think that's gonna work on the ones that have got sub-menu items, because those ones don't have a closing </li> because it's closed after the sub-menu item list...*sigh*

I can't see a way round that one at the moment unless I alter the html slightly and put a class on for whether it's a main menu item or a sub-menu item and then somehow do an if/else, but I'm not quite sure how I'd do that...:)

..unless I could do the preg_replace just on the <li><a href="filename.php">Item</a> portion of it....not sure if that would work....may do...

...then of course, do I want a title on the menu items?...I supoose I could do that on a case/break and add the variable from that into the above menu_include.php preg_replace bit....something like...

	$currentPage = basename($_SERVER['PHP_SELF']);
   $title = '';

   
   switch ($currentPage) {
       case 'index.php':
           $title = "Home page";
           break;

       case 'designs.php':
           $title = "The company's design page";
           break;

       etc.
       etc.


That might just work. Definitely time for bed now. I'll tackle that tomorrow.

_____________________________

~~ "A cruel god ain't no god at all" ~~
~~ Erase hate. Practice love. ~~
:)

(in reply to womble)
jaybee

 

Posts: 14207
Joined: 10/7/2003
From: Berkshire, UK
Status: offline

 
RE: PHP includes problem - any ideas - 1/16/2007 8:10:52   
Why are you using PHP for this rather than CSS?

_____________________________

If it ain't broke..... fix it until it is.
:)

:)
GAWDS
Now where did I put that Doctype?

(in reply to womble)
womble

 

Posts: 5721
Joined: 3/14/2005
From: Living on the edge
Status: offline

 
RE: PHP includes problem - any ideas - 1/16/2007 11:36:28   
The list's styled with CSS, but because the whole menu's an include and I don't want to faff about putting a "current" style on the body or anything (cos I know I'll forget when I add new pages in), I can't just put a "current" style on the menu item because the same file's included on all the pages for ease of maintenance, so I'd get the same menu item highlighted on all the pages.....plus I like playing about with PHP scripts and taking them to pieces and seeing if they still work when I've finished messing...:)

_____________________________

~~ "A cruel god ain't no god at all" ~~
~~ Erase hate. Practice love. ~~
:)

(in reply to jaybee)
jaybee

 

Posts: 14207
Joined: 10/7/2003
From: Berkshire, UK
Status: offline

 
RE: PHP includes problem - any ideas - 1/16/2007 12:37:41   
quote:

and seeing if they still work when I've finished messing...
Hmmmmmmm

_____________________________

If it ain't broke..... fix it until it is.
:)

:)
GAWDS
Now where did I put that Doctype?

(in reply to womble)
womble

 

Posts: 5721
Joined: 3/14/2005
From: Living on the edge
Status: offline

 
RE: PHP includes problem - any ideas - 1/17/2007 9:25:28   
Lesson 1: Listening to Auntie Jaybee's usually a good idea :)

The PHP works well as long as you've not got sub-menus, but after looking around for alternative PHP, I discovered that I was probably somewhere on the right lines with the if/else thing (at least that was one type of solution I found) but don't know enough about PHP to figure out where I was going wrong...or that I needed something a hell of a lot more complicated....

...at which point I decided that it wasn't worth the hassle, and probably the CSS route was the easiest way...:)

_____________________________

~~ "A cruel god ain't no god at all" ~~
~~ Erase hate. Practice love. ~~
:)

(in reply to jaybee)
jaybee

 

Posts: 14207
Joined: 10/7/2003
From: Berkshire, UK
Status: offline

 
RE: PHP includes problem - any ideas - 1/17/2007 9:31:34   
Not so much of the Auntie if you don't mind.

_____________________________

If it ain't broke..... fix it until it is.
:)

:)
GAWDS
Now where did I put that Doctype?

(in reply to womble)
Page:   [1]
OutFront Discoveries

All Forums >> Web Development >> General Web Development >> PHP includes problem - any ideas
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts