Posted By

S_Park on 07/30/10


Tagged

wordpress category


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

osirisinternet


Wordpress: Retrieve post categories outside of the loop


 / Published in: PHP
 

  1. <?php
  2. $ID = $wp_query->posts[0]->ID;
  3. $postcat = get_the_category($ID);
  4. $cat = $postcat[0]->cat_ID;
  5. $parent = get_category ($cat);
  6. if ($parent->parent) {
  7. wp_list_categories ('child_of=' . $parent->parent);
  8. } else {
  9. wp_list_categories ('child_of=' . $cat);
  10. }
  11. ?>

Report this snippet  

You need to login to post a comment.