How to make categories and current page highlighting in PHP?
Posted
by Markus Ossi
on Stack Overflow
See other posts from Stack Overflow
or by Markus Ossi
Published on 2010-06-14T11:55:54Z
Indexed on
2010/06/14
12:02 UTC
Read the original article
Hit count: 238
php
|categories
I am trying to find some example code or best practices about making CMS-type categories with PHP.
This is a problem that has for sure been solved gazillion times but for some reason I am unable to find any example code using PHP about how to implement this.
As far as I can tell, there are two parts to the problem. The first one has to with the styling side of things:
- outputting the link in the navigation so that the current page has a special style (class="active") and
- to not print out the link for the current page.
The second part is handling categories, subcategories and the dynamic pages under the categories.
The second part seems pretty straightforward. I am thinking of making it so that the name of the category in the navigation is a link to categories.php?id=x and on this page I just print out the pages with that category id. Then, if the user klicks on a page he will be taken to pages.php?id=y.
However, I am not quite sure on how to make a navigation to check if we are now on the current page. Should I just use some case switch or what?
Any ideas or links to some good example code are much appreciated.
© Stack Overflow or respective owner