How to list particular categories posts in wordpress?
We found many people asking that, “How to show posts of a particular category in wordpress?”, We can’t stop our self to write the code for it, so that the wordpress users can breathe easily.
You can use the wordpress’s default functions to display the desired output. Here we are using get_posts() function of wordpress. The name itself suggests that it is used to get the posts. 🙂
Here is the code to list down the posts of a particular category :
global $post; $args = array( 'numberposts' => 5, 'offset'=> 1, 'category' => CATEGORY_ID ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); ?>
You can also use the different combinations of below arguments to get your desired output. If you don’t want to do then we are here to do it for you. 🙂
'numberposts' => 5, 'offset' => 0, 'category' => , 'orderby' => 'post_date', 'order' => 'DESC', 'include' => , 'exclude' => , 'meta_key' => , 'meta_value' => , 'post_type' => 'post', 'post_mime_type' => , 'post_parent' => , 'post_status' => 'publish' ); ?>
Don’t forget to replace the CATEGORY_ID with your categorie’s id whose posts you want to list down.
You can add your own html format for listing the posts.
Its pretty Simple !!! 🙂
Let's Discuss a Project
Please share your unique idea or project requirement with us, our business concern person will get back to you with further details.