簡體   English   中英

顯示wordpress中從最新到最早的評論

[英]Display comments from the most recent to the oldest in wordpress

我試圖獲取與某個帖子相關的wordpress數據庫的所有評論,我決定必須啟用它們並將它們顯示在頁面中,從最新到最舊。 這些注釋是帶有子字段的自定義字段。 有沒有辦法做到這一點?

到目前為止,我已經在wordpress網站上編寫了以下代碼:

    $texts = get_post_meta($post->ID, "texts", true);

    if( $texts ) {
        for( $i = 0; $i < $texts; $i++ ) {
            $comment_text = get_post_meta( $post->ID, 'texts_' . $i . '_comment_text', true );
            $comment_displayed = get_post_meta( $post->ID, 'texts_' . $i . '_comment_displayed', true);
            if ($comment_text && $comment_displayed) {
                $user = get_post_meta( $post->ID, 'texts_' . $i . '_user', true );
                $user = getUserById($user);
                $text_date = get_post_meta($post->ID, 'texts_' . $i . '_text_date', true );
                echo $user->display_name;
                echo html_entity_decode($comment_text);
                echo $text_date;
                }
         }
         }

檢查是否有效?

function reverse_comments($comments,$id) {
    $comments = array_reverse($comments);
    return $comments;
}
add_filter('comments_array','reverse_comments',10,2);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM