Category Template: How Do I Show the Post of Just One Category? (5 posts)

  1. integritymedia
    Posted 2 years ago #

    So I am having some trouble just showing the posts in one category. Every time I have tried, I get the white screen of death. Here is where I am starting (which shows all categories and I just want to show ONE category). I have no idea what I am doing but like to try to figure these things out.

    	  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	  query_posts(array('post_type' => 'post', 'paged'=>$paged));
    	  if(have_posts()) : while(have_posts()): the_post();

    Any help would be much appreciated.

    Thanks in advance!

  2. webbrewers
    Posted 2 years ago #

    Doesn't a link to a specific category work? If you're looking for something else, you probably need a new category archive template with a conditional prefacing the loop code.

  3. iamthestreets
    Posted 2 years ago #

    I am still pretty new to WordPress and PHP, but I hope this helps.

    Have you tried adding 'cat=1' (change 1 to your category number) inside of query_posts?

    If you want multiple category's you can try 'category__and' => array(1,3), you would add this inside of query_posts(array('category__and' => array(1,3),));

    Let me know if this helps.

  4. integritymedia
    Posted 2 years ago #

    Didn't work :/

    I should clarify that I want to display ALL posts for one particular category (the title is a bit misleading).

    I also tried:

    <?php $args = array(
            'posts_per_page'   => 5,
            'offset'           => 0,
            'category'         => get_cat_ID( 'success' ),
            'orderby'          => 'post_date',
            'order'            => 'DESC',
            'include'          => '',
            'exclude'          => '',
            'meta_key'         => '',
            'meta_value'       => '',
            'post_type'        => 'post',
            'post_mime_type'   => '',
            'post_parent'      => '',
            'post_status'      => 'publish',
            'suppress_filters' => true );
            if(have_posts()) : while(have_posts()): the_post();

    [Moderator Note: Please post code & markup between backticks (not single quotes) or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

    This still shows all posts...no good...Any suggestions?

  5. webbrewers
    Posted 2 years ago #

    I'm not sure I understand how that is different from clicking a category (which shows all posts in that category)? Or are you trying to display posts outside a category page?

Topic Closed

This topic has been closed to new replies.

About this Topic