I using this:
<ul>
<?php wp_list_pages("&post_type=projects&child_of=$parent_page&title_li="); ?>
</ul>
To get that:
<ul>
<li class="page_item page-item-588"><a href="#" title="One">One</a></li>
<li class="page_item page-item-592"><a href="#" title="Two">Two</a></li>
<li class="page_item page-item-599"><a href="#" title="Three">Three</a></li>
</ul>
First code should display list of child pages.
Everything is fine, But i faced with some problem. If i used custom post type (like projects
in example), WordPress 3.2.1 can’t add “current” class to <LI>
and i can’t highlight random opened current page.
functions.php
add_action( 'init', 'register_cpt_projects' );
function register_cpt_projects() {
$labels = array(
'name' => _x( 'ÐÑоекÑÑ', 'projects' ),
'singular_name' => _x( 'ÐÑоекÑ', 'projects' ),
'add_new' => _x( 'ÐобавиÑÑ', 'projects' ),
'add_new_item' => _x( 'ÐобавиÑÑ Ð¿ÑоекÑ', 'projects' ),
'edit_item' => _x( 'ÐзмениÑÑ', 'projects' ),
'new_item' => _x( 'ÐовÑй ÐÑоекÑ', 'projects' ),
'view_item' => _x( 'ÐÑоÑмоÑÑеÑÑ', 'projects' ),
'search_items' => _x( 'ÐоиÑк пÑоекÑов', 'projects' ),
'not_found' => _x( 'ÐиÑего не найдено', 'projects' ),
'not_found_in_trash' => _x( 'ÐиÑего не Ð½Ð°Ð¹Ð´ÐµÐ½Ñ Ð² коÑзине', 'projects' ),
'parent_item_colon' => _x( 'РодиÑелÑÑкий ÐÑоекÑ:', 'projects' ),
'menu_name' => _x( 'ÐÑоекÑÑ', 'projects' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields', 'post-formats', 'page-attributes' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => false,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'page'
);
register_post_type( 'projects', $args );
};
variable
$parent_page:
// get_top_parent_page_id
function get_top_parent_page_id($id) {
global $post;
if ($post->ancestors) {
return end($post->ancestors);
} else {
return $post->ID;
}
};
Please Help!
wp_list_pages() will compare the current page to menu items and add class “current_page_item” to the li containing link to current page.
All you need to do is add
to your style.css file in the theme folder. No need to modify functions.php
Source: http://codex.wordpress.org/Template_Tags/wp_list_pages#Markup_and_styling_of_page_items
I think the best way will be to consider using
wp_nav_menu
instead ofwp_list_pages
– it is much more flexible solution and can do what you want. You’ll have to sync the menu with the list of your pages, but it can be done automatically using actions.in functions.php add this
Source: https://wordpress.stackexchange.com/a/12292/11610
Solve it with no pain and just body class 🙂
In functions.php:
In header.php:
In
<head>
sections or in footer.php:Have a nice day!
You need to add this to your functions.php:
Via http://kucrut.org/wp_list_pages-for-custom-post-types/