rozanchetta

wordpress - menu de taxonomias nos CPT

Sep 24th, 2011
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.20 KB | None | 0 0
  1. <?php
  2. // MENUS DROP DOWN NOS PAINÉIS DOS POSTS
  3. /* CPT Produtos */
  4. add_action( 'restrict_manage_posts', 'my_restrict_manage_posts' );
  5. function my_restrict_manage_posts() {
  6. global $typenow;
  7. if ($typenow == 'produtos') {
  8. $filters = array('linha');
  9. foreach ($filters as $tax_slug) {
  10. $tax_obj = get_taxonomy($tax_slug);
  11. $tax_name = $tax_obj->labels->name;
  12. echo "<select name='$tax_slug' id='$tax_slug' class='postform'>";
  13. echo "<option value=''>Mostrar $tax_name</option>";
  14. generate_taxonomy_options($tax_slug,0,0);
  15. echo "</select>";
  16. }
  17. }
  18. /* CPT Serviços */
  19. elseif ($typenow == 'servicos') {
  20. $filters = array('tipo');
  21. foreach ($filters as $tax_slug) {
  22. $tax_obj = get_taxonomy($tax_slug);
  23. $tax_name = $tax_obj->labels->name;
  24. echo "<select name='$tax_slug' id='$tax_slug' class='postform'>";
  25. echo "<option value=''>Mostrar $tax_name</option>";
  26. generate_taxonomy_options($tax_slug,0,0);
  27. echo "</select>";
  28. }
  29. }
  30. /* CPT Cadastros */
  31. elseif ($typenow == 'cadastros') {
  32. $filters = array('clientes', 'fornecedores');
  33. foreach ($filters as $tax_slug) {
  34. $tax_obj = get_taxonomy($tax_slug);
  35. $tax_name = $tax_obj->labels->name;
  36. echo "<select name='$tax_slug' id='$tax_slug' class='postform'>";
  37. echo "<option value=''>Mostrar $tax_name</option>";
  38. generate_taxonomy_options($tax_slug,0,0);
  39. echo "</select>";
  40. }
  41. }
  42.  
  43. /* CPT Documentos */
  44. elseif ($typenow == 'documentos') {
  45. $filters = array('usuarios');
  46. foreach ($filters as $tax_slug) {
  47. $tax_obj = get_taxonomy($tax_slug);
  48. $tax_name = $tax_obj->labels->name;
  49. echo "<select name='$tax_slug' id='$tax_slug' class='postform'>";
  50. echo "<option value=''>Mostrar $tax_name</option>";
  51. generate_taxonomy_options($tax_slug,0,0);
  52. echo "</select>";
  53. }
  54. }
  55. }
  56.  
  57. function generate_taxonomy_options($tax_slug, $parent = '', $level = 0) {
  58. $args = array('show_empty' => 1);
  59. if(!is_null($parent)) {
  60. $args = array('parent' => $parent);
  61. }
  62. $terms = get_terms($tax_slug,$args);
  63. $tab='';
  64. for($i=0;$i<$level;$i++){
  65. $tab.='--';
  66. }
  67. foreach ($terms as $term) {
  68. echo '<option value='. $term->slug, $_GET[$tax_slug] == $term->slug ? ' selected="selected"' : '','>' .$tab. $term->name .' (' . $term->count .')</option>';
  69. generate_taxonomy_options($tax_slug, $term->term_id, $level+1);
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment