Sunday, February 12, 2012

List of Post Category Wise in wordpress

for example show this type

Category 1
  post1
   post 2
   post3
category 2
   post 1
   post 2
Category 3
  post1
   post 2
   post3


 code :

<?php // get all the categories from the database 

 $cats get_categories();
// loop through the categries

 foreach ($cats as $cat) {
 // setup the cateogory ID 
 $cat_id$cat->term_id;
 // Make a header for the cateogry 
 echo "<h2>".$cat->name."</h2>";
 // create a custom wordpress query
 query_posts("cat=$cat_id&post_per_page=100"); 
 // start the wordpress loop! if (have_posts()) : while (have_posts()) : the_post(); ?> 
 
<?php // create our link now that the post is setup ?> 


 <a href="<?php the_permalink();?>"><?php the_title(); ?></a> 

<?php echo '<hr/>'?> 

 
<?php endwhile; endif; 

 // done our wordpress loop. Will start again for each category ?> 

 <?php // done the foreach statement ?>  





13 comments:

  1. this method is very helpful for show all post category by . thanks to sharing your knowledge

    ReplyDelete
  2. hello. if i want to display a particular category then what to do

    ReplyDelete
  3. $cat_id= 10; 10 is category id

    echo $cat->name ;

    query_posts("cat=$cat_id&post_per_page=100");
    if (have_posts()) : while (have_posts()) : the_post();

    the_title();

    endwhile; endif; ?>

    ReplyDelete
  4. how to dispaly category wise post on a particular page with specific category post .

    ReplyDelete
  5. hello. if i want to display a particular category post on a particular page than what to do.

    ReplyDelete
    Replies
    1. are you want

      Category1
      p1
      p2
      p3




      ans


      $cat_id= 10; 10 is category id

      echo $cat->name ;

      query_posts("cat=$cat_id&post_per_page=100");
      if (have_posts()) : while (have_posts()) : the_post();

      the_title();

      endwhile; endif; ?>

      Delete
  6. Hi. if i want to display a particular category then what to do.thanks for sharing
    Wordpress Developer

    ReplyDelete
  7. I am very thankful to the author to write this fruitful information.It is worth sharing for other users.Thanks once again
    Magento ecommerce Developer

    ReplyDelete
  8. How can i post this code in my theme?

    ReplyDelete
  9. i have 2 category first is mobile phone and id is 4 and second is smart phone category id is 5 when i want list post according category its show only uncategoryied category post
    also its show onlt category id1 post its not show cat id4 and cat id5 please replay me

    ReplyDelete
  10. i want to display my post as
    Category 1 Category 2
    Category 3 Category 4
    Category 1 Category 2
    ....

    ReplyDelete
  11. It feels good to find such an interesting topic on the internet like this one nowadays. I was greatly interested with what you have shared and posted with us. Thanks for this anyway.
    eCommerce Development Services Company in Bangalore | Magento developers in Bangalore

    ReplyDelete

If you Satisfied , Please Leave a comment