[wp-trac] [WordPress Trac] #17590: wp_list_pages() not setting "current_page_item" classes on custom post types
WordPress Trac
wp-trac at lists.automattic.com
Tue Apr 10 18:18:06 UTC 2012
#17590: wp_list_pages() not setting "current_page_item" classes on custom post
types
--------------------------+------------------------------
Reporter: tobiasn | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Themes | Version: 3.1
Severity: normal | Resolution:
Keywords: has-patch |
--------------------------+------------------------------
Comment (by daveleeone):
Hi Tobias, thanks for reply.
I have not seen, unfortunately, you've written back to me.
here is my code in the template:
function file:
{{{
function my_page_css_class( $css_class, $page ) {
global $post;
if ( $post->ID == $page->ID ) {
$css_class[] = 'current_page_item';
}
return $css_class;
}
add_filter( 'page_css_class', 'my_page_css_class', 10, 2 );
}}}
template file:
{{{
<?php
// create a ID of parent page to use the wp_list_page as submenu
if ($post->post_parent) {
$ancestors=get_post_ancestors($post->ID);
$root=count($ancestors)-1;
$parent = $ancestors[$root];
} else {
$parent = $post->ID;
}
?>
<ul class="submenu">
<?php
// create a Submenu for CPT's
$args = array(
'post_type' => 'event',
'child_of' => $parent,
'title_li' => __('')
);
wp_list_pages( $args );
?>
</ul>
}}}
jquery file
{{{
$(document).ready(function(){
$('.submenu
li:has(li.current_page_item)').addClass('parent_page_item');
});
}}}
I hope it helps.
if you make it I'll pay you a beer :)
--
Ticket URL: <http://core.trac.wordpress.org/ticket/17590#comment:8>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list