Jump to content

Navigation Bar CSS+php issue

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
NastyDevil

NastyDevil

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
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?

#2
Khaotic

Khaotic

    Learning Programmer

  • Members
  • PipPipPip
  • 62 posts
i suggest using javascript as it is the easiest way.
Check out my site: www.khaoticirc.net

#3
NastyDevil

NastyDevil

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
how do you do it in javascript then?

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
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.

#5
NastyDevil

NastyDevil

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
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....

#6
DataPeople

DataPeople

    Newbie

  • Members
  • Pip
  • 1 posts
Hi everyone,

How r u? All of your discussion is helpful for me & also other.

Thanks for nice post & sharing.

Best regards

DataPeople

#7
Scuby

Scuby

    Newbie

  • Members
  • Pip
  • 8 posts
hi... there's some solution how to do this...

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
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
@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.

#9
Scuby

Scuby

    Newbie

  • Members
  • Pip
  • 8 posts
Sure, it's the easiest way how to "explain" the code if someone don't know what's going on :)

#10
Khaotic

Khaotic

    Learning Programmer

  • Members
  • PipPipPip
  • 62 posts
In my opinion, javascript would be cleaner to do it in
Check out my site: www.khaoticirc.net

#11
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts

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.

#12
asdfer

asdfer

    Newbie

  • Members
  • Pip
  • 2 posts
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 :)

<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