Thesis Theme for WordPress:  Options Galore and a Helpful Support Community

Blog Within A Blog

Post image for Blog Within A Blog

in Thesis Bits

So let’s say you want more than one part of your site to utilize the ‘blog’ feature. For example, your site is about different hi-tech gadgets: cameras, computers, phones. You want to be able to update each section just as you would a blog, with your most recent posts appearing first. It’s simple to do if you’re using ‘categories.’ And if you’re using Thesis, you can place your chosen categories in the navigation.

When I first tried this, I saw that my category posts were also showing on “My Blog.” I didn’t want that duplication. So some kind soul over at DIY forums gave me the following code to keep my extra blog pages from showing on the assigned blog page. I’m pasting the code here. Just change the “-9″ to the number or name of your category. You can find it in the task bar (at the bottom of your screen) by going to the Posts-Category section, and hovering over the title with your cursor.  Look down. You’ll see a number. That’s what goes into the code below.  (preserve all spaces and punctuation)

function exclude_category($query) {
if ( $query->is_feed || $query->is_home ) {
$query->set('cat', '-9');
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category');

Now when you write your posts, just select the category and voila! it will appear on the category page and not the home page.  For Thesis users, this code goes into custom functions. If you have more than one blog section that you want restricted from the home blog page, you’ll need a function with an array. Consult the WordPress Codex for conditionals using arrays.

In short, here’s what I did:

1. Created two pages as usual.
2. Set the static page for home, set blog page for posts.
3. In thesis nav, only selected static page for home.
4. Created posts and assigned categories.
5. Selected categories to go into thesis navigation.

Then added the above code to custom functions. All done.

Previous post:

Next post: