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 trialJaco Burger
20,807 PointsExclude 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
Christopher Rebacz
10,904 PointsI'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.
Clinton Hopgood
7,825 PointsCan you not just disable / unpublish the blog page?
Jaco Burger
20,807 PointsI can, but I still want the blog page, just need it to display on a separate page.
Caroline Hagan
12,612 PointsDepends 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!
Jaco Burger
20,807 PointsJaco Burger
20,807 PointsExactly what I was looking for. Thanks!
Jaco Burger
20,807 PointsJaco Burger
20,807 PointsIf you don't mind, mind looking at this post as well? haha
https://teamtreehouse.com/forum/layout-on-onepage-wordpress-site