Just producing my first site in WordPress and am a complete newbie to PHP. I want the nav bar to show an active state identifying the page being viewed. After trying a few different pieces of code (most of which didn’t work at all) I came across this one which almost works:
$current_page = $post->ID;
$parent = 1;
$page_query = $wpdb->get_row(“SELECT post_name, post_parent FROM $wpdb->posts WHERE ID = ‘$current_page'”);
$parent = $current_page = $page_query->post_parent;
$parent_name = $page_query->post_name;
<body id=”<?php echo (is_page()) ? “$parent_name” : ((is_home()) ? “blog” : ((is_search()) ? “other” : ((is_single()) ? “blog” : “blog”))); ?>”>
My main menu has six options and this code works on four of them but not the other two (portfolio and contact). The site can be viewed here: http://www.snapdesigns.co.uk/index.php
Any help would be greatly appreciated.
- The topic ‘Body ID in PHP problem’ is closed to new replies.