0

I'm using get_pages in Wordpress to create a sub nav on a page.

I know I can use wp_list_pages but I wanted to control the links at different screen sizes in bootstrap.

Using this sort of code is it possible to indicate with a class name the current page in the sub nav.

In wp_list_pages it would be 'current_page_item'

<?php

$page_args = array(

    'child_of' => $post->post_parent,
    'sort_column' => 'ID',
    'sort_order' => 'ASC'

);

$pages = get_pages($page_args);

?>

<div class="container sub-nav">

    <div class="row">

        <div class="col-sm-1"></div>    

<?php
foreach($pages as $page){
?>

            <div class="col-sm-2">

                <a href="'. get_page_link( $page->ID ) .'">

                    <?php echo $page->post_title;?>

                </a>

            </div>
<?php
}
?>

        <div class="col-sm-1"></div>

    </div>

</div>

<?php   
?>
?>
0

You'll have to use this function get_queried_object_id(), if the ID returned by this function is equal to the ID of the page ($page->ID in your code), that's the current page.

Based on that you can add a class.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.