I have created a hierarchical custom post type called events and have used wp_list_pages
to list the sub-posts for each event post (See below). This navigation works great, but I cannot figure out how to highlight the menu items based on the post being viewed. I normally use .current_menu_item
, but this class is not generated for CPT.
Is there any way I can add this class to the link for the current post? Thank you for your help!
//If the post has a parent, get the parent id
if($post->post_parent) {
$args = array(
'title_li' => '',
'child_of' => $post->post_parent,
'post_type' => 'events',
'echo' => 0
);
//Create a variable for the parent post id
$top_page = $post->post_parent;
}
//If the post is a parent, get the post id
else {
$args = array(
'title_li' => '',
'child_of' => $post->ID,
'post_type' => 'events',
'echo' => 0
);
//Create a variable for the post id
$top_page = $post->ID;
}
//List child pages
$post_children = wp_list_pages( $args );
//Get the title of the the parent page
$top_title = get_the_title($top_page);
//Get the of permalink the parent page
$top_link = get_permalink($top_page);
//If there are children, list them in a side nav
if ( $post_children ) {
?>
<!--Sub-page side nav-->
<div id="inline-side-nav">
<a href="<?php echo $top_link; ?>"><h3><?php echo $top_title; ?></h3></a>
<ul>
<?php echo $post_children ?>
</ul>
</div>