Advertisement
supportnwl

get category parent link

Aug 29th, 2012
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. add_filter('em_category_output_placeholder','my_em_styles_placeholders',1,3);
  2. function my_em_styles_placeholders($replace, $EM_Category, $result){
  3. global $wp_query, $wp_rewrite;
  4.  
  5. switch( $result ){
  6. case '#_CATEGORYPARENT':
  7. $replace = '';
  8. $arrCategory = get_terms(EM_TAXONOMY_CATEGORY,array('parent'=>0,'hide_empty'=>0) );
  9. foreach($arrCategory as $arrterm) {
  10. $child = get_term_children($arrterm->term_id,EM_TAXONOMY_CATEGORY);
  11.  
  12. if ( (count($child) == 0) && ($EM_Category->name == $arrterm->name) ){
  13. $replace = '<a href="' . get_term_link( $EM_Category->name, EM_TAXONOMY_CATEGORY ) . '">' . $EM_Category->name .'</a>' ;
  14. }else if ( (count($child) > 0) && ($EM_Category->name == $arrterm->name) ){
  15. $replace = '<a href="' . get_term_link( $EM_Category->name, EM_TAXONOMY_CATEGORY ) . '">' . $EM_Category->name .'</a>' ;
  16. }else{
  17. foreach($child as $term_child_id) {
  18. $term_child = get_term_by('id',$term_child_id,EM_TAXONOMY_CATEGORY);
  19. if ( $term_child->name == $EM_Category->name ){
  20. $replace = '<a href="' . get_term_link( $arrterm->name, EM_TAXONOMY_CATEGORY ) . '">' . $arrterm->name . '</a>';
  21. }
  22. }
  23. }
  24.  
  25.  
  26. }
  27. }
  28. return $replace;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement