[英]How to create hierarchical structure like WordPress category using php
How to display the category structure like WordPress using php? 如何使用php显示类似WordPress的类别结构?
Array
( [0] => stdClass Object ( [cat_id] => 64 [name] => Bathing Soap [slug] => bathing-soap [cat_taxonomy_id] => 65 [taxonomy] => product_cat [parent] => 63 ) ([0] => stdClass对象([cat_id] => 64 [名称] =>沐浴皂[slug] =>沐浴皂[cat_taxonomy_id] => 65 [分类学] => product_cat [parent] => 63)
[1] => stdClass Object
(
[cat_id] => 65
[name] => Chemical
[slug] => chemical
[cat_taxonomy_id] => 66
[taxonomy] => product_cat
[parent] => 64
)
[2] => stdClass Object
(
[cat_id] => 63
[name] => Soap
[slug] => soap
[cat_taxonomy_id] => 64
[taxonomy] => product_cat
[parent] => 0
)
) )
In your example is arrays as you store this records in database. 在您的示例中是将数据存储在数据库中的数组。
For output tree structure you should convert it to tree structure. 对于输出树结构,您应该将其转换为树结构。
For example: 例如:
Step 1 you can make when you load data from fro database. 从数据库加载数据时可以执行的步骤1。 Steps 2 and 3 can make in one iteration (foreach) 步骤2和3可以在一次迭代中进行(foreach)
After this your example will similar 在此之后,您的示例将类似
array(
[0] => stdClass Object
(
[cat_id] => 0,
[childs] => array( [0]=>63 )
...
)
[63]=> stdClass Object
(
[cat_id] => 63,
[childs] => array( [0]=>64 )
...
)
Then you can output tree. 然后你可以输出树。 Just begin with key = 0 and output all childs. 只需从key = 0开始并输出所有子项。 For each child in first out title and then all childs. 对于每个孩子的头一个冠军,然后是所有孩子。 You should use recursion function. 你应该使用递归函数。
I have tried this below link. 我试过以下链接。 you can also try this below Link 你也可以尝试下面链接
http://stevenbuick.com/category-hierarchy-with-codeigniter-and-jstree/ http://stevenbuick.com/category-hierarchy-with-codeigniter-and-jstree/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.