Skip links

How to make a menu link display as active when the navigation is in a php include file

March 29, 2011

I always use this bit of code for my navigation links that are part of a php include file.

Whenever the recordset on the particular page (rs_page) is equal to the unique id from the row (in this case 1) it echoes “class=”selected”

 

<?php $pageon = $row_rs_page[‘page_id’]; $pagenumber = “1”; if ($pageon == $pagenumber) {echo ” class=\”selected\””;} ?>

… or another way would be to declare the name of each page using this at the top of your HTML (example ‘servicespage’) :

<?php $page_name = ‘servicespage’; ?>

and use this in your menu file:

<?php if($page_name == ‘servicespage’) echo ‘class=”selected”‘; ?>

chris-parker
This website uses cookies to improve your web experience.
chris-parker

Send me a message.

Happy to answer any question you may have.

chris@chrisparkerdesign.co.uk

07813 311253

    Your Name (required)

    Your Email (required)

    Subject

    Your Message

    CHRIS PARKER DESIGN

    chris@chrisparkerdesign.co.uk

    07813 311253