WordPress.org

Ready to get started?Download WordPress

Forums

wp_list_pages - Get current page class on Custom Post Types (1 post)

  1. bej-soan
    Member
    Posted 1 year ago #

    Hi there,

    i'm using a function I found in the codex to display "List topmost ancestor and its immediate children" I do this on a page with a custom post type, so not a page.

    My Problem is I need the
    ul Items to display the class "current-menu-item" to style it.

    functions.php

    if(!function_exists('get_post_top_ancestor_id')){
    /**
     * Gets the id of the topmost ancestor of the current page. Returns the current
     * page's id if there is no parent.
     *
     * @uses object $post
     * @return int
     */
    function get_post_top_ancestor_id(){
        global $post;
    
        if($post->post_parent){
            $ancestors = array_reverse(get_post_ancestors($post->ID));
            return $ancestors[0];
        }
    
        return $post->ID;
    }}

    I get the current post type also, to display different stylesheets for the CPTs (e.g a Illustrator Post has illustrator stylesheet, a photoshop post has photoshop stylesheet)

    this is my sidebar:

    <?php
    $area = get_post_type();
    global $post;
    $postID = $post->ID;
    $parent_title = get_the_title($post->post_parent);
    ?>
    
    <ul class="clearfix">
    	<li class="parent">
    	<a href="<?php echo get_permalink($post->post_parent) ?>">
    	<?php echo $parent_title;?> v </a>
    	</li>
    
    	<?php wp_list_pages(
    	array('title_li'=>'','include'=>get_post_top_ancestor_id())
    	); ?>
    
    	<?php wp_list_pages(
    	array('title_li'=>'','depth'=>1,'post_type'=>$area,'child_of'=>get_post_top_ancestor_id())
    	); ?>
    /ul>

    I found in the same codex page Markup and Styling and I am familiar with this on regular menus, but the example from the codex is just working for pages.
    How can I make the same work for my custom post type? Right now the just have the classes "page_item page-item-XY" (XY is the id)

Topic Closed

This topic has been closed to new replies.

About this Topic