Wordpress display posts in category based on page.


/ Published in: PHP
Save to your folder(s)

Had many people ask me how I display all posts in a category when they click on the category link in the header @<a href="http://www.vagrantradio.com">http://www.vagrantradio.com</a>.

There's a lot more involved, but here's the quick and dirty;


Copy this code and paste it in your HTML
  1. //if is articles page, get posts from this category id and show 9 of them.
  2. <?php
  3. if (is_page('7') ) {//articles
  4. query_posts('cat=4&showposts=9');
  5. } elseif ( is_page('9') ) {//freebies
  6. query_posts('cat=5&showposts=9');
  7. } elseif ( is_page('356') ) {//inspiration
  8. query_posts('cat=30&showposts=9');
  9. } elseif ( is_page('949') ) {//tutorials
  10. query_posts('cat=6&showposts=9');
  11. } else {
  12. $cat = '';
  13. }
  14. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.