1 wordpress highlight custom-post-type
我用这个:
<ul>
<?php wp_list_pages("&post_type=projects&child_of=$parent_page&title_li="); ?>
</ul>
Run Code Online (Sandbox Code Playgroud)
要获得:
<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>
Run Code Online (Sandbox Code Playgroud)
第一个代码应显示子页面列表。一切都很好,但是我遇到了一些问题。如果我使用自定义帖子类型(projects例如示例),则Wordpress 3.2.1无法向其中添加“当前”类,<LI>并且我也不能突出显示随机打开的当前页面。
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 );
};
Run Code Online (Sandbox Code Playgroud)
变量$ 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;
}
};
Run Code Online (Sandbox Code Playgroud)
请帮忙!
wp_list_pages()会将当前页面与菜单项进行比较,并将类“ current_page_item”添加到包含当前页面链接的li中。
您需要做的就是添加
li.current_page_item{
/*your specific mark up here */
}
Run Code Online (Sandbox Code Playgroud)
到主题文件夹中的style.css文件。无需修改functions.php
来源:http://codex.wordpress.org/Template_Tags/wp_list_pages#Markup_and_styling_of_page_items