kandi111777
kandi111777

Reputation: 9

How to remove specific children pages when using echo $children; in Wordpress

UPDATE: Fixed it!!

<?php
            $children = wp_list_pages("title_li=&child_of=".$root_parent_id."&sort_column=menu_order&echo=0&exclude=912");
            if ($children) {
            ?>

We are using the following php code in the page.php file to dynamically build our sidebar nav section; however, I need to exclude certain child pages from appearing. Any suggestions would be very helpful!

<?php
            $children = wp_list_pages("title_li=&child_of=".$root_parent_id."&sort_column=menu_order&echo=0");
            if ($children) {
            ?>
            <div class="submenu">
                <h2><?php echo get_the_title( $root_parent_id ); ?></h2>
                <ul>
                    <?php echo $children; ?>
                </ul>
            </div>

Upvotes: 0

Views: 94

Answers (1)

RiddleMeThis
RiddleMeThis

Reputation: 1345

Replace your first line with the following code. Update 12 with the IDs of your child pages that you want to exclude.

Note: I moved the parameters into $args as its easier to read and maintain,

$args = array(
    'title_li'     => '',
    'child_of'     => $root_parent_id,
    'sort_column'  => 'menu_order',
    'echo'         => 0,
    'exclude'      => '12'
); 

$children = wp_list_pages($args);

Here is more info on wp_list_page().

Upvotes: 0

Related Questions