What have you tried so far, what code have you written so far, where are you going wrong, what error does your code give you. Please edit your question and add all relevant code, effort and research. As your question currently stands, it is a do-my-work-for-me type of question, which WPSE is not
–
Pieter GoosenMay 6 '14 at 6:35

The easiest way to go about this is to first get all the categories using get_categories and then use WP_Query to create a query that will loop through the posts and return them according to the category to which they belong.

Here is the code I came up with. Proper explanation is included in the code