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

Exclude a page on One-Page WP Site

Hi Guys.

I'm currently building a one page site, where all the pages must appear, EXCEPT for the blog page. What should I do to display all the pages, except for that?

Thanks

4 Answers

I'm assuming you are trying to create something similar to Zac's One Page Site tutorial. If so, there is just one additional parameter you need to add into the WP Query args array (post__not_in) where you are looping to get the pages for your one page layout.

<?php

$blog = get_page_by_title( 'Blog' );  //replace Blog with the title of your blog

$args = array (
   'post_type' => 'page',
  'post__not_in' => array( $blog ), 
   'order' => 'ASC
);
$the_query = new WP_Query( $args );

?>

The (post_not_in) expects an array of page ids. If you already know your blog page id, you don't need to do the get_page_by title function, just add that to the array: e.g., 'post_not_in' => array ( 8 ). // assuming a page id of 8.

Having trouble with the formatting here. The double underscore between post and not is being automatically removed and bolded.

Exactly what I was looking for. Thanks!

If you don't mind, mind looking at this post as well? haha

https://teamtreehouse.com/forum/layout-on-onepage-wordpress-site

Can you not just disable / unpublish the blog page?

I can, but I still want the blog page, just need it to display on a separate page.

Depends where it is appearing; is it coming up in a menu... ? Is this a template or something you're building from scratch? Need a bit more info!