I'm presently doing the next during my wordpress theme,

    <?php

$pagelist = wp_list_pages( array( 
    'include' => '154, 136', 
    'title_li' => '', 
    'sort_column' => 'ID', 
    'sort_order' => 'DESC', 
    'depth' => '0',
    'echo' => false
));

if($post->post_type == "casestudy") {
    $args = array( 'post_type' => 'casestudy');
    $case_studies = new WP_Query( $args );
    $casestudylist = "";
    foreach ($case_studies->posts as $k => $v) {
        $active = ""; 
        if($v->post_status == "publish") {
            if($v->ID == $post->ID)
            {
                $active = "current_page";
            }
            $casestudylist .= "<li class='subnav ".$active."'><a href=".$v->guid.">". substr($v->post_title, 0, strpos($v->post_title, ':')) ."</a></li>";
        }
    }
}


$testimonials = wp_list_pages( array( 
    'include' => '318', 
    'title_li' => '', 
    'sort_column' => 'ID', 
    'sort_order' => 'DESC', 
    'depth' => '1',
    'echo' => false
));
//die(print_r($casestudylist));

$concatenatedlist = $pagelist . $casestudylist . $testimonials;

?>



<aside class="secondary">
    <nav>
        <ul>
            <?php echo $concatenatedlist; ?>
        </ul>
    </nav>
</aside>

This develops a navigation, and provides the sense that the page has some children which are constructed with custom publish types. However , if I am searching in a publish in the $casestudylist I have to in some way include an energetic class to the first link which comes from $pagelist, despite the fact that the 2 are unrelated. I do not mind if it's a jQuery solution. Essentially, if the aspect in my casestudylist is active, I have to possess the example link marked as active also.

This is actually the HTML the PHP produces.

    <aside class="secondary">
    <nav>
        <ul>
                <li class="page_item page-item-154">
                      <a href="/clients">Clients</a>
                    </li>
                    <li class="page_item page-item-136">
                        <a href="/case-study">Case Study</a
                    </li>
                    <li class="subnav current_page">
                        <a href="/?post_type=casestudy&amp;p=161">Brenntag</a>
                    </li>
                    <li class="subnav ">
                         <a href="/?post_type=casestudy&amp;p=104"></a>
                    </li>
                    <li class="subnav ">
                         <a href="?post_type=casestudy&amp;p=65"></a>
                    </li>
                    <li class="page_item page-item-318">
                        <a href="/testimonials">Testimonials</a>
                    </li>
        </ul>
    </nav>
</aside>

To get it done in jQuery you can say:

if($('li.subnav.current_page').length>0) {
    $('li.page-item-136').addClass('current_page');
}

But hard-coding the publish ID is not very robust, nor is depending on jQuery to use a method that Wordpress ought to be serving.

You will find a couple of ideas here worth considering, but my stomach reaction would be to do among the following:

  • Substitute pages with parent-child associations for that page and custom posts
  • Produce a custom taxonomy to envelop all of the pages involved, and change your theme to show it.

Findings:

  1. For hygiene sake, $casestudylist ought to be set to "" prior to the if.
  2. There's no indication you're ever engaging in the if($post->post_type == "casestudy") section.
  3. And when you had been, you'd most likely prefer to wrap the $casestudylist in <ul> to be able to nest it.