Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,092
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Problem with Highlighting Section Tab for Article

    My website consists mainly of articles, and has a header with 5 Tabs representing different Sections (i.e. Home, Finance, Legal, Management, Small Business).

    When you click on a Tab, you are taken to that Section, which displays a listing of all Articles for said Section.

    So that you know which Section you are in, I use PHP/HTML to highlight the current Section like this...

    PHP Code:
    <?php
        
    // Determine Script Name.
        
    $scriptName $_SERVER['SCRIPT_NAME'];
        
    $queryString $_SERVER['QUERY_STRING'];
    ?>
    Code:
    	<!-- TOP MENU -->
    	<ul id="topMenu">
    		<li <?php if($scriptName=="/index.php") echo 'class="current"'; ?>>
    			<a href="/">Home</a>
    		</li>
    
    		<li <?php if($queryString=="section=finance") echo 'class="current"'; ?>>
    			<a href="/finance/">Finance</a>
    		</li>
    
    		<li <?php if($queryString=="section=legal") echo 'class="current"'; ?>>
    			<a href="/legal/">Legal</a>
    		</li>
    
    		<li <?php if($queryString=="section=management") echo 'class="current"'; ?>>
    			<a href="/management/">Management</a>
    		</li>
    
    		<li <?php if($queryString=="section=small-business") echo 'class="current"'; ?>>
    			<a href="/small-business/">Small Business</a>
    		</li>
    	</ul><!-- End of #TOPMENU -->

    So all of this is working nicely when you go from the Home Page...
    http://local.debbie/

    Or from any of the Section pages...
    http://local.debbie/finance/
    http://local.debbie/legal/
    http://local.debbie/management/
    http://local.debbie/small-business/


    The problem is when you click on an actual Article and go to a path like this...
    http://local.debbie/finance/articles/postage-meters-can-save-you-money


    When you are reading an Article, the proper Tab (e.g. "Finance") is no longer highlighted.


    This is likely, because now $queryString has changed to...

    section=finance&slug=postage-meters-can-save-you-money


    How can I fix this?

    There may be a more eloquent way to achieve what I want to do, but in the very least, if I can just tell my script "If you see 'section=<something>' then use that to highlight the proper Tab, and ignore everything after that since you won't need it!"

    Would someone please help me get this fixed?

    Thanks,


    Debbie

  • #2
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    use if($_GET['section'] == 'whatever')

  • #3
    Senior Coder doubledee's Avatar
    Join Date
    Mar 2011
    Location
    Arizona
    Posts
    1,092
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by patryk View Post
    use if($_GET['section'] == 'whatever')
    Close.

    This works better...
    PHP Code:
            <li <?php echo ((isset($_GET['section']) && $_GET['section']=="finance") ? 'class="current"' ''?>>
                <a href="/finance/">Finance</a>
            </li>


    Thanks,


    Debbie

  • #4
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    i helped someone else with a similar thing a few days ago,

    if this helps

    PHP Code:

     <?php
        
    $navmenu 
    = array(
        
    'Home' => 'index.php',
        
    'Products' => array(
            
    '0' => 'products.php',
            
    'Application_Services' => 'application.php',
            
    'Operations_and_Hosting_Services' => 'operation-hosting.php',
            
    'Reporting_Software' => 'report.php',
            
    'Integration_Services' => 'integration.php',
            
    'Program_Management_Office' => 'program-management.php',
            
    'EDI_Services' => 'edi.php',
            
    'Training' => 'training.php" class="no-line'
            
    ),
        
    'About Us' => 'about-us.php',
        
    'News &amp; Events' => 'news-events.php',
        
    'Contact Us' => 'contact-us.php'
        
    );
            
    $displayedpage $_SERVER['PHP_SELF'];
    echo 
    '<ul id="nav-ul" class="box">
        '
    ;
    foreach (
    $navmenu as $title => $link){
        if (
    is_array($link)){
            if(
    stristr($displayedpage"$link") != FALSE) {$actclass =  ' class="Act"';}else{$actclass '';}
            
    $title str_replace("_"" "$title);
                echo 
    '<li'.$actclass.'><a href="'.$navmenu[$title][0].'">'.$title.'</a>
                    '
    ;
                echo 
    '<ul>
                    '
    ;
                foreach (
    $navmenu[$title] as $title1 => $link1){
                    if (
    $title1 != '0'){
                        if(
    stristr($displayedpage"$link1") != FALSE) {$actclass =  ' class="Act"';}else{$actclass '';}
                        
    $title1 str_replace("_"" "$title1);
                        echo  
    '<li'.$actclass.'><a href="'.$link1.'">'.$title1.'</a></li>
                            '
    ;
                    }
                }
                echo 
    '</ul>
                    '
    ;
        }else{
            if(
    stristr($displayedpage"$link") != FALSE) {$actclass =  ' class="Act"';}else{$actclass '';}
            
    $title str_replace("_"" "$title);
              echo  
    '<li'.$actclass.'><a href="'.$link.'">'.$title.'</a></li>
                  '
    ;
        }

    echo 
    '</ul>';
    ?>
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Posting Permissions

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