Hi, i have been able to create a navigation bar with css, but i realized that it can just be made once and "included" into every page of yours with php. Now what i dont understand is how can you edit the button that should link to that same page by doing so?
To make it clear: I have 5 links in the navigation bar. I want the user not to be able to click the button of the navigation bar when he is already on that page. EX: user is viewing About info so he shouldnt be able to click it. I am able to edit it manually if it were just an html file and i would just remove the link from whatever page it was, but if i include the bar in my page using php, how can i make sure the css for that page is changed?
Navigation Bar CSS+php issue
Started by NastyDevil, Jun 20 2010 11:03 PM
11 replies to this topic
#1
Posted 20 June 2010 - 11:03 PM
|
|
|
#2
Posted 21 June 2010 - 12:27 PM
i suggest using javascript as it is the easiest way.
Check out my site: www.khaoticirc.net
#3
Posted 21 June 2010 - 02:14 PM
how do you do it in javascript then?
#4
Posted 21 June 2010 - 02:36 PM
Heh, I don't think there's any "clean way" to do it, but you can do this:
<?php $page = $_GET['page']; //etc. ?> <li ... class="<?php print ($page == "about") ? 'nolink' : 'link' ?>">About</li> <li ... ...
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#5
Posted 21 June 2010 - 09:16 PM
Just to clarify once more what im trying to do is something like the following: ben hulse design | a grey medium photography design | vancouver bc canada
When you click on the web button on that site it becomes highlighted for that page. Now i can do this with a little different code if i make 5 pages, but how can you handle that with just 1 file as your navigation bar? I see what you have there Null but can that really work? Any solutions to this in whatever language are welcome. I might just end up making 5 pages....
When you click on the web button on that site it becomes highlighted for that page. Now i can do this with a little different code if i make 5 pages, but how can you handle that with just 1 file as your navigation bar? I see what you have there Null but can that really work? Any solutions to this in whatever language are welcome. I might just end up making 5 pages....
#6
Posted 23 June 2010 - 09:19 PM
Hi everyone,
How r u? All of your discussion is helpful for me & also other.
Thanks for nice post & sharing.
Best regards
DataPeople
How r u? All of your discussion is helpful for me & also other.
Thanks for nice post & sharing.
Best regards
DataPeople
#7
Posted 25 June 2010 - 05:58 AM
hi... there's some solution how to do this...
if your url looks like for example
then u will set through htaccess that "slozka" would match $page variable, "scuby" would match $subpage variable and "Vendulka" would be a $subsubpage variable...
your menu could now look like:
so let's make it through PHP:
i hope that helped little bit... it's just one of hundreds solutions in PHP
if your url looks like for example
http://duck.pacevt.com/slozka/scuby/Vendulka
then u will set through htaccess that "slozka" would match $page variable, "scuby" would match $subpage variable and "Vendulka" would be a $subsubpage variable...
your menu could now look like:
<a href="/link_one">Link one</a> <a href="/link_two">Link two</a> <a href="/link_three">Link three</a> <a href="/link_four">Link four</a>
so let's make it through PHP:
<?php
if($_GET['page'] == 'link_one'){$href_one = 'href="/link_one"';}else{$href = '';}
if($_GET['page'] == 'link_two'){$href_two = 'href="/link_two"';}else{$href = '';}
if($_GET['page'] == 'link_three'){$href_three = 'href="/link_three"';}else{$href = '';}
if($_GET['page'] == 'link_four'){$href_four = 'href="/link_four"';}else{$href = '';}
echo'
<a '.$href_one.'>Link one</a>
<a '.$href_two .'>Link two</a>
<a '.$href_three .'>Link three</a>
<a '.$href_four .'>Link four</a>
';
i hope that helped little bit... it's just one of hundreds solutions in PHP
#8
Posted 25 June 2010 - 05:07 PM
@Scuby, that looks like an alright solution, although you best just slam it into IF statements.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#9
Posted 26 June 2010 - 05:38 AM
Sure, it's the easiest way how to "explain" the code if someone don't know what's going on :)
#10
Posted 26 June 2010 - 09:52 AM
In my opinion, javascript would be cleaner to do it in
Check out my site: www.khaoticirc.net
#11
Posted 26 June 2010 - 06:18 PM
Khaotic said:
In my opinion, javascript would be cleaner to do it in
JS can be slow and broken for something as simple as this, a preprocessor to handle addition or omission of the hyperlink is ideal, JS would just be a hack more or less at runtime.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#12
Posted 27 June 2010 - 12:44 AM
Just edit the bolded text to match your structure.
I didn't checked it with menu include in pages with php, but I copied it in two page and it worked :)
best regards, hope it works for you,
asdfer
I didn't checked it with menu include in pages with php, but I copied it in two page and it worked :)
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
var sPath = window.location.pathname;
//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
$(document).ready(function() {
$("[B]#asdfasdfasdf a[/B]").attr("href", function (arr) {
var as = $(this).attr("href");
if(sPage==as) return "#";
})
.each(function () {
$("[B]a[/B]", this).attr("href", this);
});
});
</script>
best regards, hope it works for you,
asdfer


Sign In
Create Account


Back to top









