Timber\Post::comments PHP Метод

comments() публичный Метод

Gets the comments on a Timber\Post and returns them as an array of TimberComments (or whatever comment class you set).
public comments ( integer $count, string $order = 'wp', string $type = 'comment', string $status = 'approve', string $CommentClass = 'Timber\Comment' ) : boolean | array
$count integer Set the number of comments you want to get. `0` is analogous to "all"
$order string use ordering set in WordPress admin, or a different scheme
$type string For when other plugins use the comments table for their own special purposes, might be set to 'liveblog' or other depending on what's stored in yr comments table
$status string Could be 'pending', etc.
$CommentClass string What class to use when returning Comment objects. As you become a Timber pro, you might find yourself extending TimberComment for your site or app (obviously, totally optional)
Результат boolean | array
    public function comments($count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'Timber\\Comment')
    {
        global $overridden_cpage, $user_ID;
        $overridden_cpage = false;
        $commenter = wp_get_current_commenter();
        $comment_author_email = $commenter['comment_author_email'];
        $args = array('post_id' => $this->ID, 'status' => $status, 'order' => $order);
        if ($count > 0) {
            $args['number'] = $count;
        }
        if (strtolower($order) == 'wp' || strtolower($order) == 'wordpress') {
            $args['order'] = get_option('comment_order');
        }
        if ($user_ID) {
            $args['include_unapproved'] = array($user_ID);
        } elseif (!empty($comment_author_email)) {
            $args['include_unapproved'] = array($comment_author_email);
        }
        $comments = get_comments($args);
        $timber_comments = array();
        if ('' == get_query_var('cpage') && get_option('page_comments')) {
            set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1);
            $overridden_cpage = true;
        }
        foreach ($comments as $key => &$comment) {
            $timber_comment = new $CommentClass($comment);
            $timber_comments[$timber_comment->id] = $timber_comment;
        }
        // Build a flattened (depth=1) comment tree
        $comments_tree = array();
        foreach ($timber_comments as $key => $comment) {
            if (!$comment->is_child()) {
                continue;
            }
            $tree_element = $comment;
            do {
                $tree_element = $timber_comments[$tree_element->comment_parent];
            } while ($tree_element->is_child());
            $comments_tree[$tree_element->id][] = $comment->id;
        }
        // Add child comments to the relative "super parents"
        foreach ($comments_tree as $comment_parent => $comment_children) {
            foreach ($comment_children as $comment_child) {
                $timber_comments[$comment_parent]->add_child($timber_comments[$comment_child]);
                unset($timber_comments[$comment_child]);
            }
        }
        $timber_comments = array_values($timber_comments);
        return $timber_comments;
    }