当前位置: 首页>>代码示例>>PHP>>正文


PHP Walker_Comment类代码示例

本文整理汇总了PHP中Walker_Comment的典型用法代码示例。如果您正苦于以下问题:PHP Walker_Comment类的具体用法?PHP Walker_Comment怎么用?PHP Walker_Comment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Walker_Comment类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_comment_pages_count

/**
 * Calculate the total number of comment pages.
 *
 * @since 2.7.0
 *
 * @uses Walker_Comment
 *
 * @global WP_Query $wp_query
 *
 * @param array $comments Optional array of WP_Comment objects. Defaults to $wp_query->comments
 * @param int   $per_page Optional comments per page.
 * @param bool  $threaded Optional control over flat or threaded comments.
 * @return int Number of comment pages.
 */
function get_comment_pages_count($comments = null, $per_page = null, $threaded = null)
{
    global $wp_query;
    if (null === $comments && null === $per_page && null === $threaded && !empty($wp_query->max_num_comment_pages)) {
        return $wp_query->max_num_comment_pages;
    }
    if ((!$comments || !is_array($comments)) && !empty($wp_query->comments)) {
        $comments = $wp_query->comments;
    }
    if (empty($comments)) {
        return 0;
    }
    if (!get_option('page_comments')) {
        return 1;
    }
    if (!isset($per_page)) {
        $per_page = (int) get_query_var('comments_per_page');
    }
    if (0 === $per_page) {
        $per_page = (int) get_option('comments_per_page');
    }
    if (0 === $per_page) {
        return 1;
    }
    if (!isset($threaded)) {
        $threaded = get_option('thread_comments');
    }
    if ($threaded) {
        $walker = new Walker_Comment();
        $count = ceil($walker->get_number_of_root_elements($comments) / $per_page);
    } else {
        $count = ceil(count($comments) / $per_page);
    }
    return $count;
}
开发者ID:hadywisam,项目名称:WordPress,代码行数:49,代码来源:comment-functions.php

示例2: wp_list_comments

/**
 * List comments
 *
 * Used in the comments.php template to list comments for a particular post
 *
 * @since 2.7.0
 * @uses Walker_Comment
 *
 * @param string|array $args Formatting options
 * @param array $comments Optional array of comment objects.  Defaults to $wp_query->comments
 */
function wp_list_comments($args = array(), $comments = null)
{
    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
    $in_comment_loop = true;
    $comment_alt = $comment_thread_alt = 0;
    $comment_depth = 1;
    $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '');
    $r = wp_parse_args($args, $defaults);
    // Figure out what comments we'll be looping through ($_comments)
    if (null !== $comments) {
        $comments = (array) $comments;
        if (empty($comments)) {
            return;
        }
        if ('all' != $r['type']) {
            $comments_by_type =& separate_comments($comments);
            if (empty($comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $comments_by_type[$r['type']];
        } else {
            $_comments = $comments;
        }
    } else {
        if (empty($wp_query->comments)) {
            return;
        }
        if ('all' != $r['type']) {
            if (empty($wp_query->comments_by_type)) {
                $wp_query->comments_by_type =& separate_comments($wp_query->comments);
            }
            if (empty($wp_query->comments_by_type[$r['type']])) {
                return;
            }
            $_comments = $wp_query->comments_by_type[$r['type']];
        } else {
            $_comments = $wp_query->comments;
        }
    }
    if ('' === $r['per_page'] && get_option('page_comments')) {
        $r['per_page'] = get_query_var('comments_per_page');
    }
    if (empty($r['per_page'])) {
        $r['per_page'] = 0;
        $r['page'] = 0;
    }
    if ('' === $r['max_depth']) {
        if (get_option('thread_comments')) {
            $r['max_depth'] = get_option('thread_comments_depth');
        } else {
            $r['max_depth'] = -1;
        }
    }
    if ('' === $r['page']) {
        if (empty($overridden_cpage)) {
            $r['page'] = get_query_var('cpage');
        } else {
            $threaded = -1 == $r['max_depth'] ? false : true;
            $r['page'] = 'newest' == get_option('default_comments_page') ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
            set_query_var('cpage', $r['page']);
        }
    }
    // Validation check
    $r['page'] = intval($r['page']);
    if (0 == $r['page'] && 0 != $r['per_page']) {
        $r['page'] = 1;
    }
    if (null === $r['reverse_top_level']) {
        $r['reverse_top_level'] = 'desc' == get_option('comment_order') ? TRUE : FALSE;
    }
    extract($r, EXTR_SKIP);
    if (empty($walker)) {
        $walker = new Walker_Comment();
    }
    $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r);
    $wp_query->max_num_comment_pages = $walker->max_pages;
    $in_comment_loop = false;
}
开发者ID:klr2003,项目名称:sourceread,代码行数:89,代码来源:comment-template.php

示例3: my_theme_comments

function my_theme_comments()
{
    $id = get_the_ID();
    $avatar = get_avatar();
    $coms = wp_list_comments(array('echo' => false));
    $comments = get_comments(array('post_id' => $id));
    $walker = new Walker_Comment();
    $output = $walker->paged_walk($comments, -1, '', '');
    $in_comment_loop = false;
    echo $output;
}
开发者ID:rbelow,项目名称:doingitwrong,代码行数:11,代码来源:template-tags.php

示例4: ping

 /**
  * Same as Walker_Comment::ping() plus some Bootstrap classes and style locked on `div`.
  *
  * @param WP_Comment $comment The comment object.
  * @param int        $depth   Depth of the current comment.
  * @param array      $args    An array of arguments.
  */
 protected function ping($comment, $depth, $args)
 {
     ob_start();
     parent::ping($comment, $depth, array_merge($args, ['style' => 'div']));
     echo str_replace(['class="comment-body"'], ['class="comment-body well well-sm"'], ob_get_clean());
 }
开发者ID:kadimi,项目名称:bootswatch,代码行数:13,代码来源:comment-walker.php

示例5: foreach

 function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output)
 {
     if (!$element) {
         return;
     }
     $id_field = $this->db_fields['id'];
     $id = $element->{$id_field};
     parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
     // If we're at the max depth, and the current element still has children, loop over those and display them at this level
     // This is to prevent them being orphaned to the end of the list.
     if ($max_depth <= $depth + 1 && isset($children_elements[$id])) {
         foreach ($children_elements[$id] as $child) {
             $this->display_element($child, $children_elements, $max_depth, $depth, $args, $output);
         }
         unset($children_elements[$id]);
     }
 }
开发者ID:vanie3,项目名称:appland,代码行数:17,代码来源:frontend.php

示例6: foreach

 function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output)
 {
     if (!$element) {
         return;
     }
     $id_field = $this->db_fields['id'];
     $id = $element->{$id_field};
     // we add li tags only in 0 depth comments
     if ($depth == 0) {
         ?>
         <li class="media media-comment"><?php 
     }
     parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
     // If we're at the max depth, and the current element still has children, loop over those and display them at this level
     // This is to prevent them being orphaned to the end of the list.
     if ($max_depth <= $depth + 1 && isset($children_elements[$id])) {
         foreach ($children_elements[$id] as $child) {
             $this->display_element($child, $children_elements, $max_depth, $depth, $args, $output);
         }
         unset($children_elements[$id]);
     }
     // we add li tags only in 0 depth comments
     if ($depth == 0) {
         ?>
         </li><?php 
     }
 }
开发者ID:rinodung,项目名称:wordpress-demo,代码行数:27,代码来源:frontend.php


注:本文中的Walker_Comment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。