gpt4 book ai didi

php - 品类深层功能

转载 作者:可可西里 更新时间:2023-10-31 23:50:04 25 4
gpt4 key购买 nike

如何在此函数上使用空格填充来获得深度类别。目前我有选择框,所有类别都具有相同的级别。

<?php
add_action('add_meta_boxes', 'my_custom_metabox');
function my_custom_metabox() {
add_meta_box('custom-taxonomy-dropdown','Brands','taxonomy_dropdowns_box','post','side','high');
}

function taxonomy_dropdowns_box( $post ) {
global $brand_taxonomy, $taxonomy_name;
wp_nonce_field('custom-dropdown', 'dropdown-nonce');
$terms = get_terms( $brand_taxonomy, 'hide_empty=1&hierarchical=1;');
if ( is_a( $terms, 'WP_Error' ) ) {
$terms = array();
}

$object_terms = wp_get_object_terms( $post->ID, $brand_taxonomy, array('fields'=>'ids'));
if ( is_a( $object_terms, 'WP_Error' ) ) {
$object_terms = array();
}

// you can move the below java script to admin_head
?>

<?php


wp_dropdown_categories('show_option_none=Select category&show_count=1&hierarchical=1&taxonomy=ad_cat');



echo "Brand:";
echo "<select id='custombrandoptions' name='custombrands[]'>";
echo "<option value='0'>None</option>";
foreach ( $terms as $term ) {

if ( in_array($term->term_id, $object_terms) ) {
$parent_id = $term->term_id;
echo "<option value='{$term->term_id}' selected='selected'>{$term->name}</option>";
} else {
echo "<option value='{$term->term_id}'>{$term->name}</option>";
}

}
echo "</select><br />";



echo '<input type="text" value="'.$meta = get_post_meta($post->ID, 'cat_include', true).'" />';

}

来源:http://paste.php.lv/dc485b1e6f37f09f916fccc6ae70ed2f?lang=php

最佳答案

我不确定您的问题出在哪里,但也许您正在寻找 fpr str_repeat http://php.net/manual/en/function.str-repeat.php ..

所以你可以使用这些方式:

echo '<option value="" ..>'.str_repeat(' ',$currentLevel+1).'</option>';

(我不明白你是如何获得深度的。也许通过层次结构递归迭代是个好主意。)

关于php - 品类深层功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7885667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com