問題描述

現在,這些自定義帖子類型和其他一些內容不一定需要按時間順序按日期組織,例如:客户端有一個 100 T-Shirts 作為自定義帖子類型”SHIRT”,他想設置他們的外觀順序。

您建議採取什麼方式讓網站的編輯/管理員排序他們的訂單?

最佳解決方案

我可以建議這些:

http://drewgourley.com/order-up-custom-ordering-for-wordpress/

次佳解決方案

您可以過濾關於分類學

        // to filter by category
    function restrict_manage_posts() {
        global $typenow;

        if ( FB_CPT_POST_TYPE_1 == $typenow ) {
            $args = array('orderby' => 'count', 'hide_empty' => true);
            echo $this->get_taxonomy_html_select(FB_CPT_TAXONOMY_TYPE_1, $args);
        }
    }

    function get_taxonomy_html_select($taxonomy_name, $args) {

        $taxonomy = get_taxonomy($taxonomy_name);
        $terms = get_terms($taxonomy_name, $args);
        $label = __( 'Show all ' . $taxonomy->label, FB_CPT_TEXTDOMAIN );
        $html = array();
        $html[] = '<select style="min-width:155px;" id="' . $taxonomy_name . '" name="' . $taxonomy_name . '" class="postform">';
        $html[] = '<option value="0">' . $label . '</option>';
        if ( isset($_GET[$taxonomy_name]) )
            $this_term = $_GET[$taxonomy_name];
        else
            $this_term = '';
        foreach($terms as $term) {
            $default = ( $this_term == $term->term_id ? ' selected="selected"' : '' );
            $value = esc_attr($term->name);
            $value = $value . '&nbsp;&nbsp;(' . (int)$term->count . ')';
            $html[] = "t" . '<option value="' . $term->term_id . '"' . $default . '>' . $value . '</option>';
        }
        $html[] = '</select>' . "n";
        return implode( "n", $html );
    }

    function request($request) {
        global $pagenow;

        if ( is_admin() && 'edit.php' == $pagenow && isset( $request[FB_CPT_TAXONOMY_TYPE_1] ) && FB_CPT_POST_TYPE_1 == $request[FB_CPT_TAXONOMY_TYPE_1] ) {
            $request['taxonomy'] = FB_CPT_TAXONOMY_TYPE_1;
            $request['term'] = get_term($request[FB_CPT_TAXONOMY_TYPE_1], FB_CPT_TAXONOMY_TYPE_1)->name;
            unset($request['name']);
        }

        return $request;
    }

使用這個鈎子

            // to filter custom post type per custom taxonomy
        add_action( 'restrict_manage_posts', array( &$this, 'restrict_manage_posts') );
        add_action( 'request', array( &$this, 'request' ) );

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。