Advertisement
eappereira

Listar subcategorias Wordpress

Jan 27th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. * Elton Pereira - eltondeveloper@gmail.com
  5. * Listar subcategorias Wordpress
  6. *
  7. *
  8. * Abaixo pegaremos todas subcategorias da categoria id=10
  9. */
  10.  
  11. wp_list_categories('orderby=name&show_count=1&child_of=10&order=desc');
  12.  
  13.  
  14. /*
  15. * Uma outra forma de montar a listagem:
  16. */
  17.  
  18. global $sub_cats;
  19.  
  20. // Usarei novamente como base modelo a categoria id=10
  21. $childcats = get_categories('orderby=name&child_of=10&show_count=1');
  22.  
  23.     foreach ($childcats as $childcat) {
  24.          if (cat_is_sub_cats_of($sub_cats, $childcat->cat_ID) == false){
  25.             echo '<li><a href="'.get_category_link($childcat->cat_ID).'">';
  26.             echo $childcat->cat_name . '</a>';
  27.             echo '</li>';
  28.          $sub_cats = $childcat->cat_ID;
  29.       }
  30. }
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement