管理中的Wordpress分类过滤器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了管理中的Wordpress分类过滤器相关的知识,希望对你有一定的参考价值。

  1. add_action( 'restrict_manage_posts', 'my_restrict_manage_posts' );
  2. function my_restrict_manage_posts() {
  3.  
  4. // only display these taxonomy filters on desired custom post_type listings
  5. global $typenow;
  6. if ($typenow == 'photos' || $typenow == 'videos') {
  7.  
  8. // create an array of taxonomy slugs you want to filter by - if you want to retrieve all taxonomies, could use get_taxonomies() to build the list
  9. $filters = array('plants', 'animals', 'insects');
  10.  
  11. foreach ($filters as $tax_slug) {
  12. // retrieve the taxonomy object
  13. $tax_obj = get_taxonomy($tax_slug);
  14. $tax_name = $tax_obj->labels->name;
  15. // retrieve array of term objects per taxonomy
  16. $terms = get_terms($tax_slug);
  17.  
  18. // output html for taxonomy dropdown filter
  19. echo "<select name='$tax_slug' id='$tax_slug' class='postform'>";
  20. echo "<option value=''>Show All $tax_name</option>";
  21. foreach ($terms as $term) {
  22. // output each select option line, check against the last $_GET to show the current option selected
  23. echo '<option value='. $term->slug, $_GET[$tax_slug] == $term->slug ? ' selected="selected"' : '','>' . $term->name .' (' . $term->count .')</option>';
  24. }
  25. echo "</select>";
  26. }
  27. }
  28. }

以上是关于管理中的Wordpress分类过滤器的主要内容,如果未能解决你的问题,请参考以下文章