Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Ari Winokur
PLUS
Ari Winokur
Courses Plus Student 6,844 Points

Order of pages on one page WordPress theme

I have been working with the workshop on making a single page WordPress site. I want to change the order the pages display. How do I do that?

2 Answers

Ari,

In the file 'one-page-site.php', in the arguments for the WP_Query, it is currently set to ascending order:

<?php 
    $args = array(
         'post_type' => 'page',
          'order' => 'ASC'
     );
     $the_query = new WP_Query( $args );            
?>

The line 'order' => 'ASC' determines the post order. You can change it to DESC to put it in descending order, or just go in and change the dates on each page to alter their order.

You could also probably add the parameter 'orderby' => 'date' to exercise more control. Change 'date' to any other parameter, examples would be:

  • none - No order
  • ID - Sort by post ID (make sure it's capitalized)
  • author - Sort by author
  • title - Sort by title
  • parent - Order by post/page parent
  • rand - Sort randomly
  • menu_order - Sort by page order
Ari Winokur
PLUS
Ari Winokur
Courses Plus Student 6,844 Points

Thanks Josh! That was exactly the step I needed, adding the "orderby" gave me the control I needed!