【发布时间】:2016-05-13 03:35:52
【问题描述】:
有没有办法将所有 wordpress post cmets 放入一个嵌套(线程)的 php 对象或数组中?
我需要一个嵌套对象的原因是因为这个嵌套对象可以很容易地传递给模板引擎以输出一个 HTML 模板,其中所有 cmets 及其嵌套回复都正确显示。
cmets 对象所需/理想的格式如下:
{
"015":{
"comment_content":"Nullam in magna quis libero posuere vestibulum.",
"comment_date":"2016-05-13 00:20:32",
"other_comment_args":"...",
"replies":{
}
},
"837":{
"comment_content":"Nullam in magna quis libero posuere vestibulum.",
"comment_date":"2016-05-13 00:20:32",
"other_comment_args":"...",
"replies":{
"015":{
"comment_content":"Nullam in magna quis libero posuere vestibulum.",
"comment_date":"2016-05-13 00:20:32",
"other_comment_args":"...",
"replies":{
"015":{
"comment_content":"Nullam in magna quis libero posuere vestibulum.",
"comment_date":"2016-05-13 00:20:32",
"other_comment_args":"...",
"replies":{
}
},
"234":{
"comment_content":"Nullam in magna quis libero posuere vestibulum.",
"comment_date":"2016-05-13 00:20:32",
"other_comment_args":"...",
"replies":{
}
}
}
},
"125":{
"comment_content":"Nullam in magna quis libero posuere vestibulum.",
"comment_date":"2016-05-13 00:20:32",
"other_comment_args":"...",
"replies":{
}
},
"654":{
"comment_content":"Nullam in magna quis libero posuere vestibulum.",
"comment_date":"2016-05-13 00:20:32",
"other_comment_args":"...",
"replies":{
}
}
}
},
"785":{
"comment_content":"Nullam in magna quis libero posuere vestibulum.",
"comment_date":"2016-05-13 00:20:32",
"other_comment_args":"...",
"replies":{
"015":{
"comment_content":"Nullam in magna quis libero posuere vestibulum.",
"comment_date":"2016-05-13 00:20:32",
"other_comment_args":"...",
"replies":{
}
},
"231":{
"comment_content":"Nullam in magna quis libero posuere vestibulum.",
"comment_date":"2016-05-13 00:20:32",
"other_comment_args":"...",
"replies":{
}
},
"554":{
"comment_content":"Nullam in magna quis libero posuere vestibulum.",
"comment_date":"2016-05-13 00:20:32",
"other_comment_args":"...",
"replies":{
}
}
}
}
}
我已经研究过使用 'get_cmets' wordpress 功能。但是,这会返回一个包含单个级别的所有 cmets 的数组。任何子评论(回复 cmets)都有一个带有父评论 ID 的“comment_parent”属性。这是函数返回值的 print_r 的样子。
[1] => WP_Comment Object
(
[comment_ID] => 5644
[comment_parent] => 0
[comment_post_ID] => 332
[comment_author_email] => commenter@localhost
[comment_date] => 2016-05-13 00:20:32
[comment_content] => i. Nullam in magna quis libero posuere vestibulum. Donec mi leo, elementum ut.
)
[2] => WP_Comment Object
(
[comment_ID] => 8738
[comment_parent] => 5644
[comment_post_ID] => 332
[comment_author_email] => commenter@localhost
[comment_date] => 2016-05-13 00:20:32
[comment_content] => i. Nullam in magna quis libero posuere vestibulum. Donec mi leo, elementum ut.
)
[3] => WP_Comment Object
(
[comment_ID] => 7758
[comment_parent] => 5644
[comment_post_ID] => 332
[comment_author_email] => commenter@localhost
[comment_date] => 2016-05-13 00:20:32
[comment_content] => i. Nullam in magna quis libero posuere vestibulum. Donec mi leo, elementum ut.
)
自定义评论漫游器可能会有所帮助,但是我没有遇到任何评论漫游器使用评论对象填充嵌套对象的示例。
提前谢谢你。
【问题讨论】:
标签: php wordpress wordpress-theming