Thread Starter
ChrisR
(@chrisr)
I’ve worked out a plugin which i’m going to clean up a little, strip the dirty code and i’ll post it here … only drawback is the immense number of queries if you got quite a big hierarchical layout in the pages. But we’ll have to live with that i’m afraid 🙂
I have contacted Chris, and he kindly sent me the code he has used for his website (Thanks Chris!).
I am going to try to implement this:
<?php
$highlightclass = "current_page_item";
// highlight 'Blog' if not Page or Home
if (is_home()) {
$homehighlight = $highlightclass;
} elseif (is_page("blog")) {
$highlight = $highlightclass;
} elseif (is_page()) {
$highlight = "";
} else {
$highlight = $highlightclass;
}
if( is_page() ) {
$post_name = page_parents();
}
rewind_posts();
//echo "<pre>".print_r($post_name, true)."</pre>";
?>
<div id="navigation">
<li class="<?php echo $homehighlight; ?>">">Home
<li class="<?php echo $highlight; ?>">/blog/">Blog
<?php list_pages_highlighted('exclude=2,3&title_li=&depth=1&highlightall=1&sort_column=menu_order'); ?>
</div>
I’m also trying to figure this out – the above code doesn’t work for me.
I get the error: Call to undefined function: page_parents()
Did you manage to sort this out Chris or Johan?
I’ve tried to put some alternative code together (re: http://codex.wordpress.org/index.php?title=Dynamic_Menu_Highlighting&redirect=nothough it ain’t bloody working :()
<div id="mainNav">
<div>
<ul>
<li id="one"><a href="#">Home</a></li>
<li id="two"><a href="#">Services</a></li>
<li id="three"><a href="#">About</a></li>
<li id="four"><a href="#">Contact</a></li>
</ul>
</div>
</div>
<?php
$parent_id = $page_query->ID;
if ($parent_id = 3) { $current = 'one'; }
elseif ($parent_id = 5) { $current = 'two'; }
elseif ($parent_id = 2) { $current = 'three'; }
elseif ($parent_id = 4) { $current = 'four'; }
?>
Cany anyone help?
Cheers
Can anyone shed any light on this or am I in the wilderness?
I have done it this way with David Chait’s function:
<?php
function is_page_or_subpage($id)
{ /* this can be used instead of is_page FOR PAGE ID TESTS ONLY */
global $wp_query;
if (! $wp_query->is_page) {
return false;
}
if (empty($id)) {
return true;
}
$page_obj = $wp_query->get_queried_object();
if ($id == $page_obj->ID) {
return true;
}
$pages = get_pages();
foreach ($pages as $page) {
if ($page->ID == $page_obj->ID /* found the page we're on */
&& $page->post_parent == $id) /* parent matched the passed ID! */
return true;
}
return false;
}
?>
<div id="mainNav">
<div>
<ul>
<?php if(is_page_or_subpage(3)): ?>
<li class="page_item"><a href="#" title="Home"><span>Home</span></a></li>
<li class="page_item current_page_item"><a href="#" title="Services"><span>Services</span></a></li>
<?php else : ?>
<li class="page_item current_page_item"><a href="#" title="Home"><span>Home</span></a></li>
<li class="page_item"><a href="#" title="Services"><span>Services</span></a></li>
<?php endif; ?>
</ul>
</div>
</div>
johanvanderwijk: Trying to implement the same thing you have, however i’m getting an error
Fatal error: Call to undefined function: page_parents() in...
Can you let us all know how you’ve implemented this functionality?
Johan kindly replied referncing the following thread:
http://wordpress.org/support/topic/55775?replies=5