Sexytime Posted June 20, 2011 Share Posted June 20, 2011 Hi all, (I'm not incredibly knowledgeable in this kind of stuff, so please bear with me) I've recently moved my header element on my page into its own file so that when I make changes, it only needs to be done once - unlike before, where it was a code in every single page, and to make changes I needed to edit every page. It's been done and all works just like before, except for one thing - because the old header was in every single page, I was able to use <li id="current"> tags to keep the current page highlighted. But now, being a separate file, it's not going to work just like that. So for now I've removed it from the header. I did some searching and stumbled upon this page: http://codex.wordpress.org/Dynamic_Menu_Highlighting It seems to be really close to what I want, but obviously this is specific to wordpress. I've tried it out, but the is_page code seems to be what's returning errors. But I'm not sure what (if anything) I should replace them with. I'm using <?= $PageTitle ?> on each page, and I thought that might be something I can use to make my "current" tag work, but I can't figure out how to use that in the code given on the wordpress page (if it's even right). In case it helps in seeing what I'm doing wrong, my site is http://rawrockmilitia.com (I know, it's an eyesore - working on making it more readable), and the header can be found at http://rawrockmilitia.com/header.php. Does anybody have any idea of what I can do with it? Link to comment https://forums.phpfreaks.com/topic/239933-dynamic-nav-bar/ Share on other sites More sharing options...
Sexytime Posted June 21, 2011 Author Share Posted June 21, 2011 Any thoughts at all into what I'm doing? Link to comment https://forums.phpfreaks.com/topic/239933-dynamic-nav-bar/#findComment-1232782 Share on other sites More sharing options...
TeNDoLLA Posted June 21, 2011 Share Posted June 21, 2011 Your text is very confusing. But have you included the header.php file in the places where you want to use its variables? Or did I not understood what you mean? Link to comment https://forums.phpfreaks.com/topic/239933-dynamic-nav-bar/#findComment-1232784 Share on other sites More sharing options...
Sexytime Posted June 21, 2011 Author Share Posted June 21, 2011 I think you misunderstood, I probably made this way more complicated than it is. I think it's the other way around, I want to use variables from other pages in the header.php. I'll try to be as coherent as possible (as you can tell, I don't have an incredible amount of experience in this). In all of my pages, I'm using a code like this: <?php $PageTitle = "example"; include ('header.php'); ?> So the header is showing up perfectly, no problems there. Now my header.php looks like this: <div id="header-wrap"> <div id="header" class="container_16"> <h1 id="logo-text"><a href="index.php"><?= $PageTitle ?></a></h1> <p id="intro">welcome to Showbread's official street-team </p> <!-- navigation --> <div id="nav"> <ul> <li><a href="index.php">Home</a></li> <li><a href="http://forum.rawrockmilitia.com">Forum</a></li> <li><a href="http://blog.rawrockmilitia.com/">Blog</a></li> <li><a href="donate.php">Donate</a></li> <li><a href="contact.php">Contact</a></li></ul> </div> <div id="header-image"></div> The way it was set up before, the header was not its own file; all this code was placed into each page separately, and therefore could easily use "current" tags. Everything was static. In the css, the "current" page would just look like it was being hovered over. Example: if you were on the Contact page, the code would look like this: <li id="current"><a href="contact.php">Contact</a></li> Now, since it's more dynamic, I can't do it that way. I've been looking into ways to make this work. The wordpress page seems to give me an idea of what I want: <ul id="navigation"> <li id="one"><a href="#">Page One</a></li> <li id="two"><a href="#">Page Two</a></li> <li id="three"><a href="#">Page Three</a></li> <li id="four"><a href="#">Page Four</a></li> </ul> <?php if ( is_page('Page One') ) { $current = 'one'; } elseif ( is_page('Page Two') ) { $current = 'two'; } elseif ( is_page('Page Three') ) { $current = 'three'; } elseif ( is_page('Page Four') ) { $current = 'four'; } ?> But I'm not on wordpress, so the is_page up there means nothing if applied to my site. I'm trying to think of a way that I could make this work. That's why I mentioned the "$PageTitle" that I use - it's more just an idea, I don't know if I could actually use it this way, but in my head it makes sense that I could do something with it. Hopefully this is less confusing than before. Link to comment https://forums.phpfreaks.com/topic/239933-dynamic-nav-bar/#findComment-1232823 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.