0

I am wondering how to include a custom post type archive in wp_list_pages.

If there were a page ID, I could simply attach that page to the list using the 'include' argument. I know that there is a 'post_type' argument as well... but that will only list the posts, not the archive, and I need this link to be inserted alongside pages.

Is there any way for me to pull this off? Here is the code I'm using:

$parentID    = get_top_parent_id($post->ID);
$parentTitle = get_the_title($parentID);
$parentLink  = get_permalink($parentID);

$args = array(
    'child_of' => $parentID
);

$pages = get_pages($args);

if ($pages) {

    $pageIDs = array();

    foreach ($pages as $page) {
        $pageIDs[] = $page->ID;
    }

    $args = array(
        'title_li' => '',
        'include' => $parentID . ',' . implode(",", $pageIDs)
    );

    wp_list_pages($args);

}

UPDATE

Since it seemed like I wasn't going to be able to solve this the way I wanted to, I ended up taking a different approach. I found the question "Display a portion/ branch of the menu tree using wp_nav_menu()" and Rarst's answer is pretty amazing. Below is my little bit of code for creating the sidebar menu that I needed (I use WPML - hence the ICL_object):

<?php
/*
 * PAGE SIDEBAR
 *
*/

$parentID   = get_top_parent_id($post->ID);
$parentLink = get_permalink($parentID);

if ( is_singular( 'custom_post_type_NAME' ) ) {
    $cptParentID = icl_object_id( 77, 'page', false );
    $parentTitle = get_the_title($cptParentID);
} else {
    $parentTitle = get_the_title($parentID);
}

$navArgs = array(
    'menu'    => 51,
    'submenu' => $parentTitle,
    'items_wrap' => '%3$s',
    'container' => false
);

?>

    <article id="news-widget" class="widget postloop list-widget">

        <h5>
            <a href="<?php echo $parentLink; ?>" class="widget-title" title="<?php echo $parentTitle; ?>"><?php echo $parentTitle; ?></a>
        </h5>

        <nav id="secondary-navigation" class="nav-secondary">

            <ul class="pages-navlist">
                <?php wp_nav_menu($navArgs); ?>
            </ul>

        </nav>

    </article>
0

My suggestion would be create a simple list of pages by yourself and then tag on the archives you want.

You can use get_post_type_archive_link() to grab the link of any archive you need.

If you could explain more about what it is you need exactly I can knock up some example code for you.

  • I would vote up your answer... but I don't have the rep points to allow for it :( Thanks though. I ended up taking a different approach that in the end works a bit better for me, but I could of definitely managed a solid solution with a conditional and the get_post_type_archive_link() - Thanks again! – beefchimi Jan 15 '14 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.