Posted By

nerdfiles on 03/12/09


Tagged

php wordpress category


Versions (?)

Generate Category List by Category Name


 / Published in: PHP
 

  1. <?php
  2. $beforeHtml = "<div id='' class=''>";
  3. $afterHtml = "</div>";
  4. $result = "<ul class='catlist'>";
  5. $categoryName="nameOfCategory"; //Category Name
  6. $numberOfPosts=10; //Number of posts
  7. $catposts = get_posts('category_name='.$categoryName."&numberposts=".$numberOfPosts);
  8. foreach($catposts as $single):
  9. $result .= "<li><a href='";
  10. $result .= get_permalink($single->ID)."'>".$single->post_title."</a> <span class='catlistpostcomment'>(".$single->comment_count.")</span></li>";
  11. endforeach;
  12. $result .= "</ul>";
  13. $htmlList = $beforeHtml . $result . $afterHtml;
  14. echo $htmlList;
  15. ?>

Report this snippet  

You need to login to post a comment.