Grow your CSS skills. Land your dream job.

WordPress – Pages displaying out of order

  • # January 18, 2012 at 4:41 pm

    I’m listing out all my wordpress pages and a little bit of their content using a foreach loop like the following:

    < ?php
    $allPageIDs = get_all_page_ids();
    foreach($allPageIDs as $pageID) {
    $page_data = get_page( $pageID );
    $content = apply_filters('the_content', $page_data->post_content);
    $title = $page_data->post_title;
    ?>

    < ?php echo $title; ?>


    < ?php echo $content; ?>


    < ?php
    }
    ?>

    However, there is a problem. They’re displaying out of order. Since it’s going by page id, it’s going in the order that I created them, and not their set post order. Any Idea how I can fix this?

    # January 19, 2012 at 1:22 am

    Have you had a look at get_pages()?

    It would be something like:

    $pages = get_pages();
    foreach ( $pages as $page ) {

    $content = $page->post_content; // I'm not sure if it's post_content. print_r( $page ); to see what you should use
    $title = $page->post_title;

    $output = '

    ' . $title . '

    ';
    $output .= '
    ' . $content . '
    ';

    echo $output;

    }
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".