Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using the Boldy theme from Site5 on a v3.1.2 site.

The way this theme works, is that there is a portfolio, (which I am using as a case studies gallery) that pulls in posts from a specific category you define under the themes settings (id=98)

This is fine if you also set the blog up as per the Boldy instructions, where all blog posts come under a category called blog, but this wasnn't going to give me the slugs I wanted, so I adopted to use a static page called blog to show my posts on.

This all works fine, apart from the fact that the posts I create for my portfolio/case studies gallery (category = case studies) now appear in my blog as well.

Is there a way to hide posts within a specific category within the blog, but for it not to have the same affect in my case studies gallery?

--EDIT-- With some help from Wyck via the comments, made some progress. Here is a txt version of my themes default index.php file.

If I insert the following onto Line 2:

<?php query_posts($query_string . '&cat=-98'); ?>

= This results in no posts being shown on my Downloads page, but all posts still appearing on my Blog page.

I need the vice versa of this. I am sure I am close, but perhaps I need to modify which line I put this on?

--EDIT x2-- Now using the download monitor for my downloads gallery. But using the portfolio for my case studies. So some of the links above have changed, but the problem is exactly the same.

share|improve this question
    
So you don't want downloads to appear on your main blog -- is that what you're saying? –  ZaMoose Apr 27 '11 at 13:39
    
Yes that is correct. In the long run, ill be also using the portfolio for a 'case studies' page. Therefore ill also need to exclude case study posts from the blog page. –  Simon Apr 28 '11 at 4:24
    
what you want can be achieved by modifying the query to exclude a particular category but I am not sure of the code to modify it, it will probably be 4-5 lines –  Ashfame Apr 28 '11 at 7:52
    
ok I think I have got it working, will post an answer soon. I need to study your question what behavior do you exactly want it to do on various pages. –  Ashfame Apr 28 '11 at 8:21
    
@simon Take a look at my answer and let me know if it does what you want –  Ashfame Apr 28 '11 at 8:29
show 2 more comments

5 Answers

up vote 6 down vote accepted

You want the category 98 to be excluded only on the blog page, right? They should be accessible on the category page directly (your downloads page), correct?

Can you try this? Let me know if its not what you want, we can modify it to suit your needs. Right not it only excludes the category on where you show your blog posts.

add_action('pre_get_posts', 'block_cat_query' );

function block_cat_query() {
    global $wp_query;   
    if( is_home() ) {
        $wp_query->query_vars['cat'] = '-98';
    }
}
share|improve this answer
    
This has worked! Im going to hold off marking this as an answer until ive done some full testing. Thanks loads Ashfame. –  Simon Apr 28 '11 at 9:55
    
Great! As a test checkout the different pages where you want those particular posts to be shown or not to be shown and let me know :) –  Ashfame Apr 28 '11 at 10:16
    
@Simon Great! You didn't even bother to take a few secs to award the bounty. –  Ashfame May 4 '11 at 15:41
    
I thought marking the anser as resolved awarded u the bounty? –  Simon May 5 '11 at 10:49
    
Sorry man, ive flagged for a moderator to re-direct the bounty to you. Its first time ive made use of the bounty feature. I figured it went to the one I marked as the answer –  Simon May 5 '11 at 10:50
show 3 more comments

In Settings -> Reading if your Front Page is not set to show "Latest Posts" whatever is selected as posts page will use the index.php template.

I do use a static page, but I think it still uses index.php to populate items on this static page? I checked by fiddling some free text in index.php and it was reflected in the blog posts on the static page. – Simon 4 hours ago

Your comment is correct your "static page" is using index.php

To use a static page with a custom template for your blog post change your reading settings as follows:

Change This:

enter image description here

To This:

enter image description here

For your custom template just copy and paste index.php to create a new file and name it custom-page-blog.php and add this to it.

<?php
/*
Template Name: Blog
*/
    get_header();

            $args=array(
                'category__not_in' => 98
                );
                $blog_query = new WP_Query( $args );

             while ($blog_query->have_posts()) : $blog_query->the_post(); ?>        

            <!-- Begin .postBox -->
            <div class="postItem">

                    <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1> 
                    <div class="meta">
                                <?php the_time('M j, Y') ?> &nbsp;&nbsp;//&nbsp;&nbsp; by <span class="author"><?php the_author_link(); ?></span> &nbsp;&nbsp;//&nbsp;&nbsp;  <?php the_category(', ') ?>  &nbsp;//&nbsp;  <?php comments_popup_link('No Comments', '1 Comment ', '% Comments'); ?> 
                            </div>
                    <?php the_content(__('Read more >>')); ?>   
            </div>
            <!-- End .postBox -->
            <?php endwhile; ?>
                <!--<div class="navigation">
                            <div class="alignleft"><?php next_posts_link() ?></div>
                            <div class="alignright"><?php previous_posts_link() ?></div>
                </div>-->
                <?php if (function_exists("emm_paginate")) {
                    emm_paginate();
                } ?>

            </div>
            <!-- End #colLeft -->

    <?php get_sidebar(); ?> 
    <?php }?>
    <?php get_footer(); ?>

Go to your static "Blog" Page and select the new template in page atributes.enter image description here

share|improve this answer
    
Thanks for this. However, im not sure how this solves the problem? The new template file will still need tweaking to remove a category from it? Why dont we just do this to the index.php? Also where you tell me to add that php line, to me it looks like you have opened a php tag but not closed it? –  Simon Apr 28 '11 at 9:09
    
@Simon I edited the answer and included the whole custom-page-blog.php template. This template will show all the posts not in category 98. –  Chris_O Apr 28 '11 at 9:25
    
Really appreciate your efforts here. You approach does look like it will work, however, Ashfame's answer does not require me to create a new template file, so would appear to be better? Still testing... –  Simon Apr 28 '11 at 9:59
    
His approach is great and much simpler. Choose what works best for you. –  Chris_O Apr 28 '11 at 10:01
add comment

if you use static page to show the blog post, add the wyck's code to template that used for that page.

share|improve this answer
    
I do use a static page, but I think it still uses index.php to populate items on this static page? I checked by fiddling some free text in index.php and it was reflected in the blog posts on the static page. –  Simon Apr 28 '11 at 3:25
add comment

Why don't you use something like WordPress Download Monitor?

share|improve this answer
    
Ill have a look at this. Although still need my orig Q answered, as ill be using the portfolio template again for a category for Case Studies, so will still need to know how to exclude that category from the blog, and only the blog. –  Simon Apr 28 '11 at 3:23
    
Im now using this for my downloads. However, as per the edits in my Q, I am using the portfolio for my 'case studies' Same problem persists where case studies show up in blog. –  Simon Apr 28 '11 at 7:16
add comment

It's difficult to tell since you supplied no code but removing a category from your blog loop is typically very easy.

For instance above the main loop, if your category "portfolio" has an id=12 :

query_posts( 'cat=-12' );
share|improve this answer
    
Which php file will this be in? Ive done a search for 'query_posts' in all PHP files in my theme and cant find it. –  Simon Apr 17 '11 at 3:32
    
query_posts alters the "main loop" of your blog (usually index.php), you will have to add it yourself. codex.wordpress.org/The_Loop –  Wyck Apr 17 '11 at 4:52
    
Thanks, been reading up on this. Q1 - How do I find out what ID a category is? Do I need to dive into the database tables? Q2 - My theme has its own index.php. Still not too sure which line to place the query_posts in: dekho.com.au/index.txt –  Simon Apr 18 '11 at 9:14
1  
The easiest way to find the category ID is to click your category in Admin and just hover over one and you will see the ID on mouseover or in your browser ( in Chrome it shows at bottom ). –  Wyck Apr 18 '11 at 13:37
    
Hi Wyck. I found out that the category I want to exclude is 98, but I have not been able to fit it in the right place in my index.php file (see above link to see the code for this file) Any ideas? –  Simon Apr 27 '11 at 3:56
show 8 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.