0

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;
?>

1 Answer 1

2

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

5
  • 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? Feb 21, 2013 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? Feb 21, 2013 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.
    – Brooke.
    Feb 21, 2013 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.
    – Brooke.
    Feb 21, 2013 at 16:30
  • @DextrousDave Will you mark this as "solved?"
    – Brooke.
    Feb 21, 2013 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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