www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] active page

Hybrid View

  1. #1
    Join Date
    Nov 2013
    Posts
    18

    resolved [RESOLVED] active page

    Hi!

    So my problem is that I got a number of pages that I gather from my database and output in a echo. I then want to make a highlight which displays what pages you on.
    I have managed by myself to make it highlight the selected page when you click it but I can't manage to get the index page to get highlighted when visiting for example
    "www.test.com" I have to be on a page like this "www.test.com/index" for it to work. Hard to explain but I will show you my code and it might become more clearly.

    php:

    PHP Code:
    $sqlmenu mysql_query ("SELECT id, label FROM pages ORDER BY pageorder ASC");

        
    $menuDisplay '';
        while(
    $row mysql_fetch_array($sqlmenu)){
            
    $mid $row["id"];
            
    $label $row["label"];
            
            
    $menuDisplay .= '<li><a href="index.php?mid=' $mid '">' $linklabel '</a></li>';
        } 
    Javascript:
    Code:
    $(document).ready(function(){
            var i = document.location.href.lastIndexOf("/");
            var currentPHP = document.location.href.substr(i+1);
            $("ul#main-menu li a").removeClass('activeNavBtn');
            $("ul#main-menu li a[href^='"+currentPHP+"']").addClass('activeNavBtn');
      });
    Thanks!

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    Code:
    ...
    var currentPHP = document.location.href.substr(i+1)||'index.php';
    ...
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  3. #3
    Join Date
    Nov 2013
    Posts
    18
    Thank you that helped alot!

    ||'index.php?mid=1';

    Was the exact answer, forgot to say that "home" had a static number of 1...
    but it was enough to make me figure it out so many thanks!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles