自定义分类的Wordpress前端

时间:2013-06-29 07:28:41

标签: php wordpress wordpress-plugin custom-taxonomy

这是用于人们选择类别以提交列表的类别的Wordpress前端表单 我的自定义分类标准是“位置” 但是下面的代码显示了'listcat'的自定义分类,我如何编辑它以显示'位置'分类?     

<div class="form_row">

    <div class="label">

        <label for="category"><?php echo CATEGORY; ?><span class="required">*</span></label>

    </div>

    <div class="field">

        <div style="height:100px; width: 290px; overflow-y:scroll; margin-bottom: 15px;">

            <?php

            global $wpdb;

            $taxonomy = CUSTOM_CAT_TYPE;

            $table_prefix = $wpdb->prefix;

            $wpcat_id = NULL;

            //Fetch category                          

            $wpcategories = (array) $wpdb->get_results("

                    SELECT * FROM {$table_prefix}terms, {$table_prefix}term_taxonomy

                    WHERE {$table_prefix}terms.term_id = {$table_prefix}term_taxonomy.term_id

                    AND {$table_prefix}term_taxonomy.taxonomy ='" . $taxonomy . "' and  {$table_prefix}term_taxonomy.parent=0  ORDER BY {$table_prefix}terms.name ASC");



            $wpcategories = array_values($wpcategories);

            if ($wpcategories) {

                echo "<ul class=\"select_cat\">";

                if ($taxonomy == CUSTOM_CAT_TYPE) {

                    ?>

                    <li><label><input type="checkbox" name="selectall" id="selectall" class="checkbox" onclick="displaychk_frm();" /></label><?php echo SLT_ALL; ?></li>



                    <?php

                }

                foreach ($wpcategories as $wpcat) {

                    $counter++;

                    $termid = $wpcat->term_id;

                    $name = $wpcat->name;

                    $termprice = $wpcat->term_price;

                    $tparent = $wpcat->parent;

                    ?>

                    <li><label><input class="list_category" type="checkbox" name="category[]" id="<?php echo $termid; ?>" value="<?php echo $name; ?>" class="checkbox" /><?php echo $name; ?></label></li>

                    <?php

                    $args = array(

                        'type' => POST_TYPE,

                        'child_of' => $termid,

                        'parent' => '',

                        'orderby' => 'name',

                        'order' => 'ASC',

                        'hide_empty' => 0,

                        'hierarchical' => 1,

                        'exclude' => '',

                        'include' => '',

                        'number' => '',

                        'taxonomy' => CUSTOM_CAT_TYPE,

                        'pad_counts' => false);

                    $acb_cat = get_categories($args);



                    if ($acb_cat) {

                        echo "<ul class=\"children\">";

                        foreach ($acb_cat as $child_of) {

                            $term = get_term_by('id', $child_of->term_id, CUSTOM_CAT_TYPE);

                            $termid = $term->term_taxonomy_id;

                            $term_tax_id = $term->term_id;

                            $name = $term->name;

                            ?>

                            <li><label><input class="list_category" type="checkbox" name="category[]" id="<?php echo $termid; ?>" value="<?php echo $name; ?>" class="checkbox" /><?php echo $name; ?></label></li>

                            <?php

                            $args = array(

                                'type' => POST_TYPE,

                                'child_of' => $term_tax_id,

                                'parent' => '',

                                'orderby' => 'name',

                                'order' => 'ASC',

                                'hide_empty' => 0,

                                'hierarchical' => 1,

                                'exclude' => '',

                                'include' => '',

                                'number' => '',

                                'taxonomy' => CUSTOM_CAT_TYPE,

                                'pad_counts' => false);

                            $acb_cat = get_categories($args);

                            if ($acb_cat) {

                                echo "<ul class=\"children\">";

                                foreach ($acb_cat as $child_of) {

                                    $term = get_term_by('id', $child_of->term_id, CUSTOM_CAT_TYPE);

                                    $termid = $term->term_taxonomy_id;

                                    $term_tax_id = $term->term_id;

                                    $name = $term->name;

                                    ?>

                                    <li><label><input class="list_category" type="checkbox" name="category[]" id="<?php echo $termid; ?>" value="<?php echo $name; ?>" class="checkbox" /><?php echo $name; ?></label></li>

                                    <?php

                                }

                                echo "</ul>";

                            }

                        }

                        echo "</ul>";

                    }

                }

                echo "</ul>";

            }

            ?>   

        </div>                

    </div>

</div>

<!--End Row--> 

1 个答案:

答案 0 :(得分:0)

找到这一行

$taxonomy = CUSTOM_CAT_TYPE;

并将其替换为

$taxonomy = 'location';

可能有帮助,但不确定。