0

I am currently using a Plug-in that creates a "silo" structure for my website. It creates a sidebar with a list of the Parent page followed by the Child Pages. It only allows me to show the Child pages in the order that they were created. I would like to have the child pages listed in random order, Is this a possibility?

Example:

Pool Removal Contractors
-Alabama
-Arizona
-Arkansas

I found the following code here:

function wpb_list_child_pages() { 

    global $post; 

    if ( is_page() && $post->post_parent )    
        $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' .$post->post_parent . '&echo=0' );
    else
        $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );

    if ( $childpages ) {    
        $string = '<ul>' . $childpages . '</ul>';
    }

    return $string;
}

add_shortcode('wpb_childpages', 'wpb_list_child_pages');
0

The sort_column parameter of wp_list_pages() does allow items to be returned in random order using the rand option.

sort_column (string) Comma-separated list of column names to sort the pages by. Accepts 'post_author', 'post_date', 'post_title', 'post_name', 'post_modified', 'post_modified_gmt', 'menu_order', 'post_parent', 'ID', 'rand', or 'comment_count'. Default 'post_title'.

add_shortcode( 'wpb_childpages', 'wpb_list_child_pages' );
function wpb_list_child_pages() { 
    global $post; 

    if ( is_page() && $post->post_parent ) {
        $childpages = wp_list_pages( 'sort_column=rand&title_li=&child_of=' . $post->post_parent . '&echo=0' );
    } else {
        $childpages = wp_list_pages( 'sort_column=rand&title_li=&child_of=' . $post->ID . '&echo=0' );
    }

    if ( $childpages ) {    
        $string = '<ul>' . $childpages . '</ul>';
    }

    return $string;
}

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.