/**
         * Renderer for category ordering page
         */
        function display_ht_kb_article_ordering_page()
        {
            global $wpdb, $wp_locale;
            $taxonomy = 'ht_kb_category';
            $post_type = 'ht_kb';
            $post_type_data = get_post_type_object($post_type);
            if (!taxonomy_exists($taxonomy)) {
                $taxonomy = '';
            }
            //get all the categories with the get_ht_kb_categories function, note the orderby not yet working correctly
            $all_cats = get_ht_kb_categories(null, 'slug');
            //sort the categories by slug, to overcome issue with get_ht_kb_categories not sorting correctly
            $sorted_categories = array();
            //add each category to sorted categories array, using the slug as the key
            foreach ($all_cats as $key => $cat) {
                $sorted_categories[$cat->slug] = $cat;
            }
            //perform key sort
            ksort($sorted_categories);
            ?>

            <div class="wrap">
                <h2><?php 
            _e('Article Ordering', 'ht-knowledge-base');
            ?>
</h2>

                <noscript>
                    <div class="error message">
                        <p><?php 
            _e('Javascript must be enabled to use this page', 'ht-knowledge-base');
            ?>
</p>
                    </div>
                </noscript>

                <div id="ajax-response"></div>    

                <div id="ht-kb-ordering">

                <div class="hkb-ordering__header">
                    <span><?php 
            _e('Category:', 'ht-knowledge-base');
            ?>
</span>
                    <select class="hkb-cat-selector-adm">
                        <?php 
            foreach ($sorted_categories as $key => $category) {
                ?>
                            <option value="<?php 
                echo $category->term_id;
                ?>
"><?php 
                echo $category->name;
                ?>
</option>
                        <?php 
            }
            ?>
                    </select>
                </div>

                <div class="hkb-ordering__content">


                    <form action="edit.php" method="get" id="ht-kb-ordering-form"> 
                        <?php 
            foreach ($sorted_categories as $key => $category) {
                ?>
                            <ul class="sortable hkb-category-article-list hkb-category-article-list-<?php 
                echo $category->term_id;
                ?>
" data-term-id="<?php 
                echo $category->term_id;
                ?>
">
                                <?php 
                $category_articles = hkb_get_archive_articles($category, null, null, 'article_ordering');
                $order = 10;
                ?>
                                <?php 
                if (empty($category_articles)) {
                    ?>
                                    <li><?php 
                    _e('No articles in this category', 'ht-knowledge-base');
                    ?>
</li>
                                <?php 
                } else {
                    ?>
 
                                    <?php 
                    foreach ($category_articles as $key => $article) {
                        ?>
                                        <?php 
                        $custom_order = hkb_get_custom_article_order($article->ID, $category->term_id);
                        $order = empty($custom_order) ? $order : intval($custom_order);
                        ?>
                                        <li data-article-id="<?php 
                        echo $article->ID;
                        ?>
" data-term-id="<?php 
                        echo $category->term_id;
                        ?>
" data-order="<?php 
                        echo $order;
                        ?>
">
                                            <div class="item">
                                                <?php 
                        echo $article->post_title;
                        ?>
                                            </div>
                                        </li>
                                        <?php 
                        $order = $order + 10;
                        ?>
                                    <?php 
                    }
                    ?>
 
                                <?php 
                }
                ?>
                            </ul>
                        <?php 
            }
            ?>
                    </form>

                </div>

                <div class="hkb-ordering__footer">
                    <a href="javascript:;" class="save-order button-primary"><?php 
            _e("Save Order", 'ht-knowledge-base');
            ?>
</a>
                </div>

                </div>
            </div>

            <?php 
        }
示例#2
0
 /**
  * Set initial custom order meta
  */
 function ht_kb_set_initial_custom_order_meta($post_id)
 {
     //get ht_kb_category terms
     $category_terms = wp_get_post_terms($post_id, 'ht_kb_category');
     //loop terms and ensure order is set
     foreach ($category_terms as $key => $category_term) {
         $category_term_id = $category_term->term_id;
         $current_custom_order = hkb_get_custom_article_order($post_id, $category_term_id);
         //upgrade if empty, set custom order initially to post_id
         if (empty($current_custom_order)) {
             hkb_set_custom_article_order($post_id, $category_term_id, $post_id);
         }
     }
 }