Wordpress - How to get all posts related to particular category name?
Just use WP_Query()
to generate your custom query, using the category parameters.
Assuming you know (or know how to get) the ID of the specific category, as $catid
:
<?php
$category_query_args = array(
'cat' => $catid
);
$category_query = new WP_Query( $category_query_args );
?>
Note: you could also pass the category slug to the query, via category_name
, instead of cat
.
Now, just output your loop:
<?php
if ( $category_query->have_posts() ) : while $category_query->have_posts() : $category_query->the_post();
// Loop output goes here
endwhile; endif;
?>
That would depend on when and how exactly you want to use it - but generally speaking you can either use a custom query , or simply use
if in_category('my_cat_name_or_ID') {
//do whatever
}
if you want to learn about custom query : http://codex.wordpress.org/Custom_Queries