• Hello!

    I want to add class to current page item like wp_list_pages.

    I lising pages with this code.

    $args = array(
    'sort_column' => 'menu_order',
    'hierarchical' => 1,
    'exclude' => '',
    'child_of' => 0,
    'parent' => -1,
    'exclude_tree' => '',
    'number' => '',
    'offset' => 0,
    'post_type' => 'page',
    'post_status' => 'publish'
    );
    $pages = get_pages($args);
    foreach($pages as $page){
     echo '<a href="'.get_page_link( $page->ID ).'"><li>'.$page->post_title.'</li></a>';
    }

    Thanks for any reply.

Viewing 2 replies - 1 through 2 (of 2 total)
  • There is already a unique class available with current page item named “current_page_item” but if you want to add your own class for all pages or current page then you have to use Walker to achieve this.

    Thread Starter Istvan

    (@x1stvanx)

    There is no current page class

    <a href="#"><li>HOME</li></a>
    <a href="#"><li>NEWS</li></a>
    <a href="#"><li>TECH</li></a>
    <a href="#"><li>UPDATES</li></a>
    <a href="#"><li>OTHER</li></a>
    <a href="#"><li>MORE</li></a>
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘get pages current page item class’ is closed to new replies.