You’ve already got code to figure out which category you want to show posts from, here is how you would grab all the posts in that category:
// create a query to grab our posts in category of ID $postcat
$q = new WP_Query(array( 'cat' => $postcat));
if($q->have_posts()){
// foreach post found
while($q->have_posts()){
$q->the_post();
// code for displaying each post goes here
}
// cleanup after the WP_Query, reset the post data
wp_reset_postdata();
} else {
// no posts were found!
}
Never use query_posts
to do your queries, always check if any posts were actually found, and always cleanup after yourself.
For more arguements for queries, see here:
Related Posts:
- Show Custom Taxonomy Categories, Listing of Posts, and Single Post via AJAX
- Use template of parent category for single post sub-categories
- Different template for posts of all subcategories of category
- Category Template: Need to display different content on first page of archives
- How do I stop the loop from repeating in my category template?
- Post Image not displaying in category view
- Latest posts by category — how to exclude current post?
- Give posts a particular template based on the assigned category
- Remove Featured Image from posts in specific category?
- How to show category image if no featured image is set?
- Display the first post’s comments of category in comments.php template
- how to style an individual page in a category [duplicate]
- excerpt in template for specific page
- Including categories in search results
- Post/Page Preview Template
- Count how many posts in category
- Custom Single Post By Category
- Convert custom fields to post categories
- Query posts from current year
- Forcing oembeds to top of post
- Show One Category on Post
- custom single.php not working
- Do I use custom post type or something else?
- What Defines What Category A Post Picks (if in multiple)
- Delete Post From Front-End and attachment permanently
- Limit function to specific post category
- Show all post titles
- Count to how many categories a post belongs to
- How can I remove posts of a certain category from homepage after a specified time period?
- Modify WP_Post before processing
- Show featured image next to post-teasers in Genesis Framework?
- Edit custom post type admin menu link
- How to display WordPress archive into three columns [closed]
- Get mixed category random posts
- Using wp_list_categories like the the_category (showing just current categories of a post)
- Should I use posts or pages in this scenario?
- Using custom post template
- What is the filter or hook to add admin controls to posts on the front end?
- How to allow users to post only in certain category and hide elements from edit page?
- Switch to page template when using post permalink
- Genesis + Ajax + Jquery | Failling to call action
- Need help with category listing!
- Prepending %category% onto default posts fails
- List all categories with featured image from post?
- Get Page ID of blog homepage
- How to make the first post in the loop be styled like a “new / featured” post?
- Category page when using static front page
- How to create a “latest news” page showing a list of posts from blog category
- how to hide empty fields of post category description?
- How to have more than one page for your posts if you have 8 posts but can store max 4 on a page
- Extract wordpress posts content and category content
- All categories displays the same posts
- Having pages after specifying post_type post
- How to set a certain Custom Template to a Single Blog Post
- Get latest post from categories
- List all native posts in template page?
- Sidebar on single.php not showing up
- How to Featured content with images in home page?
- How to show a featured image inside a post in only 1 single category
- Highlighting Current Category in the Archive and Feeds page
- Get current taxonomy and display query accordingly
- Geting error in post and category [closed]
- Display most recent posts in category with Twenty Ten theme widget
- Display a specific category in a focused area of my site
- Post not using taxonomy template
- Does having category name in permalinks affect SEO when having a post in multiple categories?
- How to 301 redirect from url with post id to permalink with post name (slug)?
- Create/Set Category as Title of Post
- How to display related post from same category in single.php
- Save All Post Permalink From A Specific Category into a .txt file
- show image gallery in archives or category page
- Page with Category Returning 1
- How to Display Most View Post in the template file?
- get current index of post content in category page
- Dynamically load posts based on category
- Set featured image on creating new post
- Get Categories & Posts With Type Article
- Use special template for the first post in the loop
- Set multi posts random categories and tags
- Add new post only in assigned category
- Changing the Category for all posts of an Author
- How to change post template via url?
- Admin Post List Only Show One Category
- How do I get thumbnails?
- Add category attribute to custom recent post shortcode
- Same sidebar in all posts as in the category
- How do I list categories and the common categories for posts beneath those categories?
- Latest Posts not in the right order
- Retrieve latest post by multiple categories with ID
- How to Include a common category in a custom Category Search
- Redirecting posts in WordPress to a specific page
- Viewing category won’t show up Custom post type posts
- Show Title/Date/Excerpt of first post & only Title for rest in Query [duplicate]
- Listing category and its posts one by one
- Print out one of 2 post category [closed]
- How to get if category has posts?
- Show some texts in posts belonging to Specific category
- Sort Posts Alphabetically Based on Specific Category (Divi)
- I have a website issue I am trying to resolve
- How to sort posts alphabetically based on a specific parent category