1
有沒有辦法讓一個嵌套(線程)的php對象或數組中的所有WordPress的後發表評論?有沒有辦法在嵌套的php對象或數組中獲得wordpress中的所有發佈評論?
我需要一個嵌套對象的原因是因爲這個嵌套對象然後可以很容易地傳遞給一個模板引擎來輸出一個HTML模板,並且正確顯示所有註釋和嵌套的回覆。您的評論對象
所需/理想的格式會像這樣:
{
"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_comments」 WordPress的功能。但是,它會返回單個級別中所有註釋的數組。任何子女commnets(回覆評論)都有一個「comment_parent」屬性和父註釋的ID。這是函數返回值的print_r的樣子。
[1] => WP_Comment Object
(
[comment_ID] => 5644
[comment_parent] => 0
[comment_post_ID] => 332
[comment_author_email] => [email protected]
[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] => [email protected]
[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] => [email protected]
[comment_date] => 2016-05-13 00:20:32
[comment_content] => i. Nullam in magna quis libero posuere vestibulum. Donec mi leo, elementum ut.
)
定製評論步行者可能會有所幫助,但我還沒有遇到任何例子,其中一個評論沃克將填充評論的對象嵌套對象。
預先感謝您。
在努力爲了將邏輯從演示標記中分離出來,我們希望使用像樹枝,小鬍子或rainTpl這樣的誘人引擎。這意味着主題創作者可以使用普通的HTML模板,而不是混合的PHP和HTML文件。 也許有一種方法可以將「get_comments」的結果重新格式化爲分層的多級嵌套對象。 – Norman