Custom post type navigation list
-
Hi Guys,
I have a few custom post types setup, i’m using them as pages.
What I want to do is output a menu with them, using the same markup / style as wp_list_pages so that I can make it a seemless navigation.
I don’t mind splitting it out so I have 1 UL for custom-post types and one for the normal navigation.
Ideally it would look something like this…
- Custom Post Type Parent*
- Custom Post 1
- Custom Post 2
- Custom Post 3
- Custom Post Type Parent 2
- Custom Post 1
- Custom Post 2
- Custom Post 3
- Normal WP Page
- Normal WP Page
* At the moment this is a page with a template, but thinking about moving to 3.1 beta as this supports parent templating
Thanks in advance!
-
Did you happen to find an answer to this?
Not yet, i’ve got half a solution that can list custom post type pages and apply the correct style when they are active. But it’s a complete hack & I wouldn’t recommend using it.
This will create a list like this…
<?php $defaults = array( 'depth' => 1, 'title_li' => '', 'echo' => 1, 'exclude' => 6, 'sort_column' => 'menu_order, post_title', 'sort_order' => 'asc', 'link_before' => '', 'link_after' => ''); global $post, $wp_query; if (get_query_var('post_type') == 'shorts') { // Load up the 'Case Studies' page to fool WP. $page = get_page_by_title('Shorts'); $temp_post = $post; $temp_query = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $wp_query->query(array('page_id' => $page->ID)); wp_list_pages($defaults); // Restore previous wp_query. $wp_query = null; $wp_query = $temp_query; $post = $temp_post; } else if (get_query_var('post_type') == 'features') { // Load up the 'Partners' page to fool WP. $page = get_page_by_title('Features'); $temp_post = $post; $temp_query = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $wp_query->query(array('page_id' => $page->ID)); wp_list_pages($defaults); // Restore previous wp_query. $wp_query = null; $wp_query = $temp_query; $post = $temp_post; } else if (get_query_var('post_type') == 'musicvideos') { // Load up the 'Partners' page to fool WP. $page = get_page_by_title('Music Videos'); $temp_post = $post; $temp_query = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $wp_query->query(array('page_id' => $page->ID)); wp_list_pages($defaults); // Restore previous wp_query. $wp_query = null; $wp_query = $temp_query; $post = $temp_post; } else if (get_query_var('post_type') == 'virals') { // Load up the 'Partners' page to fool WP. $page = get_page_by_title('Virals'); $temp_post = $post; $temp_query = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $wp_query->query(array('page_id' => $page->ID)); wp_list_pages($defaults); // Restore previous wp_query. $wp_query = null; $wp_query = $temp_query; $post = $temp_post; } else { // A normal page. wp_list_pages($defaults); } ?>
The options at the top will change the output however most of the variables only apply to pages, not post-types. I believe it creates a list like this:
- Custom Post Type(s) – Alphabetical
- Pages – Alphabetical
maybe this is what you need: http://codex.wordpress.org/Function_Reference/wp_list_pages#List_members_of_a_custom_post_type
- The topic ‘Custom post type navigation list’ is closed to new replies.