rexrony89

Parent Catogary

Apr 28th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. Add one of these in function.php
  2. /*************************/
  3. function get_top_parent($cat){
  4. $curr_cat = get_category_parents($cat, false, '/' ,true);
  5. $curr_cat = explode('/',$curr_cat);
  6. $idObj = get_category_by_slug($curr_cat[0]);
  7. echo  $id = $idObj->term_id;
  8. }
  9.  
  10. /**********************/
  11. function get_top_parent_category($cat_ID)
  12. {
  13. $cat = get_category( $cat_ID );
  14. $new_cat_id = $cat->category_parent;
  15.  
  16. if($new_cat_id != "0")
  17. {
  18. return (get_top_parent_category($new_cat_id));
  19. }
  20. return $cat_ID;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment