2011-01-28 31 views
8

Tôi muốn ngừng WordPress sắp xếp lại danh sách danh mục trong trang quản trị bài đăng. Hành vi mặc định là đưa các danh mục được gán cho bài đăng ra khỏi luồng cha/con tự nhiên của chúng và đặt chúng ở đầu danh sách. Tôi muốn dừng điều này xảy ra vì nó gây nhầm lẫn khi cấu trúc danh mục lớn.Wordpress - Thứ tự danh sách danh mục trong trang chỉnh sửa bài đăng

Mọi suy nghĩ?

Cảm ơn.

Trả lời

6

Bạn đang sử dụng phiên bản Wordpress nào? Wordpress 3.04 cung cấp cây Parent/Child trên trang Post Edit. Bạn có chắc chắn bạn cũng không xem tab "Được sử dụng nhiều nhất" không?

Nevermind, tôi thấy chính xác những vấn đề bạn đang nói về, mà xuất hiện sau khi bài được lưu:

Cateogory Treeenter image description here

rồi, hãy thử dán này vào functions.php trong chủ đề của bạn:

// remove the old box 
function remove_default_categories_box() { 
    remove_meta_box('categorydiv', 'post', 'side'); 
} 
add_action('admin_head', 'remove_default_categories_box'); 

// add the new box 
function add_custom_categories_box() { 
    add_meta_box('customcategorydiv', 'Categories', 'custom_post_categories_meta_box', 'post', 'side', 'low', array('taxonomy' => 'category')); 
} 
add_action('admin_menu', 'add_custom_categories_box'); 

/** 
* Display CUSTOM post categories form fields. 
* 
* @since 2.6.0 
* 
* @param object $post 
*/ 
function custom_post_categories_meta_box($post, $box) { 
    $defaults = array('taxonomy' => 'category'); 
    if (!isset($box['args']) || !is_array($box['args'])) 
     $args = array(); 
    else 
     $args = $box['args']; 
    extract(wp_parse_args($args, $defaults), EXTR_SKIP); 
    $tax = get_taxonomy($taxonomy); 

    ?> 
    <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv"> 
     <ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs"> 
      <li class="tabs"><a href="#<?php echo $taxonomy; ?>-all" tabindex="3"><?php echo $tax->labels->all_items; ?></a></li> 
      <li class="hide-if-no-js"><a href="#<?php echo $taxonomy; ?>-pop" tabindex="3"><?php _e('Most Used'); ?></a></li> 
     </ul> 

     <div id="<?php echo $taxonomy; ?>-pop" class="tabs-panel" style="display: none;"> 
      <ul id="<?php echo $taxonomy; ?>checklist-pop" class="categorychecklist form-no-clear" > 
       <?php $popular_ids = wp_popular_terms_checklist($taxonomy); ?> 
      </ul> 
     </div> 

     <div id="<?php echo $taxonomy; ?>-all" class="tabs-panel"> 
      <?php 
      $name = ($taxonomy == 'category') ? 'post_category' : 'tax_input[' . $taxonomy . ']'; 
      echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. 
      ?> 
      <ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy?> categorychecklist form-no-clear"> 
       <?php 
       /** 
       * This is the one line we had to change in the original function 
       * Notice that "checked_ontop" is now set to FALSE 
       */ 
       wp_terms_checklist($post->ID, array('taxonomy' => $taxonomy, 'popular_cats' => $popular_ids, 'checked_ontop' => FALSE)) ?> 
      </ul> 
     </div> 
    <?php if (!current_user_can($tax->cap->assign_terms)) : ?> 
    <p><em><?php _e('You cannot modify this taxonomy.'); ?></em></p> 
    <?php endif; ?> 
    <?php if (current_user_can($tax->cap->edit_terms)) : ?> 
      <div id="<?php echo $taxonomy; ?>-adder" class="wp-hidden-children"> 
       <h4> 
        <a id="<?php echo $taxonomy; ?>-add-toggle" href="#<?php echo $taxonomy; ?>-add" class="hide-if-no-js" tabindex="3"> 
         <?php 
          /* translators: %s: add new taxonomy label */ 
          printf(__('+ %s'), $tax->labels->add_new_item); 
         ?> 
        </a> 
       </h4> 
       <p id="<?php echo $taxonomy; ?>-add" class="category-add wp-hidden-child"> 
        <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>"><?php echo $tax->labels->add_new_item; ?></label> 
        <input type="text" name="new<?php echo $taxonomy; ?>" id="new<?php echo $taxonomy; ?>" class="form-required form-input-tip" value="<?php echo esc_attr($tax->labels->new_item_name); ?>" tabindex="3" aria-required="true"/> 
        <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>_parent"> 
         <?php echo $tax->labels->parent_item_colon; ?> 
        </label> 
        <?php wp_dropdown_categories(array('taxonomy' => $taxonomy, 'hide_empty' => 0, 'name' => 'new'.$taxonomy.'_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '&mdash; ' . $tax->labels->parent_item . ' &mdash;', 'tab_index' => 3)); ?> 
        <input type="button" id="<?php echo $taxonomy; ?>-add-submit" class="add:<?php echo $taxonomy ?>checklist:<?php echo $taxonomy ?>-add button category-add-sumbit" value="<?php echo esc_attr($tax->labels->add_new_item); ?>" tabindex="3" /> 
        <?php wp_nonce_field('add-'.$taxonomy, '_ajax_nonce-add-'.$taxonomy, false); ?> 
        <span id="<?php echo $taxonomy; ?>-ajax-response"></span> 
       </p> 
      </div> 
     <?php endif; ?> 
    </div> 
    <?php 
} 

Thay đổi thực sự duy nhất là thêm 'checked_ontop' => FALSE vào args trong wp_terms_checklist() chức năng ở giữa đống lộn xộn đó. Mọi thứ khác là hàm post_categories_meta_box() gốc.

(Bạn chỉ có thể sửa đổi bản gốc post_categories_meta_box() trong /wp-admin/includes/meta-boxes.php, nhưng nó không được khuyến khích để gây rối với lõi và thêm/gỡ bỏ các hành động như trên là cách thích hợp để làm điều đó.

enter image description here

+0

Tôi vừa thử nghiệm tính năng này và hoạt động tốt - giải pháp tốt và dễ thực hiện. – Schoffelman

+0

Ngoài ra, bạn không có vẻ là người duy nhất khó chịu bởi "tính năng" này: từ [Wordpress Trac] (http://core.trac.wordpress.org/ticket/10982) – SideOfBacon

+0

Thật tuyệt vời, cảm ơn. –

14

Trong khi ở trên là giải pháp thay thế tuyệt vời, đặc biệt là nếu bạn muốn kiểm soát nhiều hơn đối với danh sách kiểm tra phân loại, tôi nghĩ giải pháp đơn giản nhất là:

function taxonomy_checklist_checked_ontop_filter ($args) 
{ 

    $args['checked_ontop'] = false; 
    return $args; 

} 

add_filter('wp_terms_checklist_args','taxonomy_checklist_checked_ontop_filter'); 

Và điều đó sẽ giải quyết vấn đề đó!

Các vấn đề liên quan