我想要建立一個頁面,將顯示所有評論,無論他們附加到哪個帖子。我也希望該頁面可以分頁,因爲它可能有超過10,000條評論。WordPress的獨立評論頁 - 與分頁
我不知道如何去了解它,但這裏有一些至今我研究的功能:
get_comments
- 如果沒有post_id
傳遞中,它將返回所有評論。然而,我沒有看到一種方法來分頁這些(有offset
和number
選項來擺弄,但這是很繁瑣的手動)。wp_list_comments
- 這個文檔是非常糟糕的,但the source code表明,我們可以遍歷所有的意見,如果配合使用get_comments
,由get_comments
數組中傳遞的第二個參數。然而,這實際上仍然會使用get_comments
......好吧,得到評論,似乎沒有辦法對此進行分頁。previous_comments_link
&next_comments_link
- 這些似乎與wp_list_comments
結合唯一的工作(沒有第二個參數)。paginate_comments_links
- 看起來它只適用於wp_list_comments
(沒有第二個參數)。
我已經試過什麼:
只要在
get_comments
的number
說法:$comments = get_comments(array( 'status' => 'approve', 'number' => '2' )); wp_list_comments(array( 'callback' => 'my_rendering_function' ), $comments); paginate_comments_links();
這並不顯示任何分頁鏈接。
的方法這裏建議:Display latest comments on page with pagination
$comments = get_comments(array( 'status' => 'approve' )); wp_list_comments('per_page=2', $comments); paginate_comments_links();
這也不起作用(它顯示第2個評論,但無分頁)。另外,我在
get_comments
加載全部注意到內存。
問:
我怎麼能分頁所有評論?
P.S.我使用WordPress 3.4.1 & PHP 5.3.2。
我沒有看到一個直接的方式來做到這一點,你到底需要利用'offset'和'number'來獲得需要的評論。看看SEO pager插件,你可以得到分頁功能,或者使用自定義WordPress循環來實現你的功能。 –
@ UmeshAwasthi - 你讀過[鏈接到帖子](http://wordpress.stackexchange.com/questions/7413/display-latest-comments-on-page-with-pagination)嗎?看來應該有辦法做到這一點。我誤解了什麼嗎? – MegaHit