Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using the below code to highlight the page name/gallery shown when the corresponding link is clicked on. My challenge is that regardless of what link I click, only the very first link(page_id=24/Haagen-Dazs) is highlighted. Any ideas what's causing the issue?

Thanks.

live site

CSS .active { border: 1px solid #ff893b; }

HTML/PHP/JAVA `

<p>
    <a href="?page_id=24" <?php if ($page_id=='24'){echo 'class="active"';} ?>> H&auml;agen Dazs</a><br/>
    <a href="?page_id=26" <?php if ($page_id=='26'){echo 'class="active"';} ?>> Hugo Boss Rodeo Drive</a><br/>
    <a href="?page_id=28" <?php if ($page_id=='28'){echo 'class="active"';} ?>> Ford</a><br/>
    <a href="?page_id=30" <?php if ($page_id=='30'){echo 'class="active"';} ?>> MOCA Contemporaries</a><br/>
    <a href="?page_id=32" <?php if ($page_id=='32'){echo 'class="active"';} ?>> XBOX 360 Halo 3 Sneak Preview</a><br/>
    <a href="?page_id=34" <?php if ($page_id=='34'){echo 'class="active"';} ?>> Saddlerock Smith &amp; Basso Weddings</a><br/>
    <a href="?page_id=36" <?php if ($page_id=='36'){echo 'class="active"';} ?>> Christie&apos;s</a><br/>
    <a href="?page_id=42" <?php if ($page_id=='42'){echo 'class="active"';} ?>> Instyle Magazine + Ming by Mango</a>
</p>


<script type="text/javascript">

  $(document).ready(function(){
    $('a').click(function(){
      $('a').removeClass('active');
      $(this).addClass('active');

     });

    });   

</script>

</div><!-- end client-list -->`
share|improve this question
    
Had you checked that $page_id holds expected and correct value at that point? –  Rarst Oct 1 '12 at 0:26
    
I'm not exactly sure what you mean, but links do lead to the proper pages. –  user1255049 Oct 1 '12 at 0:27
    
Your code assumes that $page_id variable holds ID of current page. You should verify that it really does (for example by echoing its value). –  Rarst Oct 1 '12 at 0:29
    
Can you provide an example? Sorry- I am still new to this. –  user1255049 Oct 1 '12 at 0:31
1  
<?php var_dump( $page_id ); ?> –  Rarst Oct 1 '12 at 0:32
show 2 more comments

2 Answers 2

up vote 1 down vote accepted

Use a WP Nav menu or the built in APIs instead. They all have current cat/active/parent highlighting on posts/pages, all out of the box

share|improve this answer
    
Menus are not available to me through Appearance > Menus (per the codex)? –  user1255049 Sep 30 '12 at 20:30
    
Thats because you need to indicate that your theme supports them via add_theme_support –  Tom J Nowell Sep 30 '12 at 20:37
add comment

Add Menu by using register_nav_menu in theme's function.php file.

you can see Appearance > Menus.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.