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 have a Page in Wordpress that is a Blog Page Template. Now my issue is that it displays ALL the posts. I only want it to display posts assigned to a certain category

How do I do that?

Here is my blog.php page: I guess you have to edit it here right?

/*
Template Name: Blog page
*/

$gogo_blog_text_no_posts = get_post_meta($post->ID, 'gogo_blog_text_no_posts', true);

$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('posts_per_page='.$gogo_blog_text_no_posts.'&paged='.$paged); 
$postcount = 0;
while ($wp_query->have_posts()) : $wp_query->the_post(); $postcount++;

//the loop goes here

$wp_query= null;
$temp = $wp_query;
?>
share|improve this question

1 Answer 1

Not sure what $gogo_blog_text_no_posts is but you should be able to change this:

$wp_query->query('posts_per_page='.$gogo_blog_text_no_posts.'&paged='.$paged);

to

$wp_query->query('posts_per_page='.$gogo_blog_text_no_posts.'&paged='.$paged.'&cat=1');

See WP_Query Codex

share|improve this answer
    
thank you BandonRandon - How do I know which posts arev category 1 ('&cat=1')...I added that line and it now shows only the default categories(which came with the theme). How do I specify my own posts as category 1 or 2 etc? –  DextrousDave Feb 21 '13 at 7:31
    
Ok cool. Got it to work using: '&category_name=***yourcategory***'. One more thing. I want to make another page with a Blog Page Template, but for this page I only want to display another category, but since it will be using the same blog.php page, how do I specify another category for a new page? –  DextrousDave Feb 21 '13 at 7:49
    
You could either a) rename the template and change the category or b) use a conditional statement (codex.wordpress.org/Conditional_Tags) to check the page slug around the wp_query although I recommend the first way. Also if this solved your issue please mark it resolved. –  BandonRandon Feb 21 '13 at 16:22
    
Also in cat=1 the 1 is that cat id which is always unique. You can get the id by using get_cat_ID (codex.wordpress.org/Function_Reference/get_cat_ID) The slug (what you did) works too as long as you don't change the name of the slug. –  BandonRandon Feb 21 '13 at 16:30
    
thank you. Appreciate your help! –  DextrousDave Feb 21 '13 at 20:00

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.