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 ?>  





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. How can i post this code in my theme?

    ReplyDelete
  8. 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
  9. i want to display my post as
    Category 1 Category 2
    Category 3 Category 4
    Category 1 Category 2
    ....

    ReplyDelete
  10. Hi there would you mind stating which blog platform you're working with?
    I'm planning to start my own blog in the near future
    but I'm having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.

    The reason I ask is because your design and style seems different
    then most blogs and I'm looking for something unique.
    P.S Apologies for being off-topic but I had to ask!

    ReplyDelete

Post a Comment

If you Satisfied , Please Leave a comment

Popular posts from this blog

Call PHP Function In JavaScript Using Ajax