本文整理汇总了PHP中wp_list_comments函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_list_comments函数的具体用法?PHP wp_list_comments怎么用?PHP wp_list_comments使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_list_comments函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_comments_tree
protected static function get_comments_tree($comments)
{
$tree = array();
if (!empty($comments)) {
$comments_by_id = array();
foreach ($comments as $comment) {
$comments_by_id[$comment->comment_ID] = $comment;
}
ob_start();
$wp_list_comments_args = array();
wp_list_comments(apply_filters('wpak_comments_list_args', $wp_list_comments_args), $comments);
$comments_list = ob_get_contents();
ob_end_clean();
//TODO : find another way to retrieve depths and ids than parsing the html (which can change!!!)
$depths_found = preg_match_all('/depth-(\\d+)/', $comments_list, $matches_depths);
$ids_found = preg_match_all('/id="comment-(\\d+)"/', $comments_list, $matches_ids);
if (!empty($depths_found) && !empty($ids_found)) {
foreach ($matches_depths[1] as $k => $depth) {
$comment_id = $matches_ids[1][$k];
$tree[$comment_id] = array('id' => $comment_id, 'depth' => (int) $depth, 'comment' => $comments_by_id[$comment_id]);
}
}
}
return $tree;
}
示例2: list_comments
public function list_comments()
{
// Prepare wp_list_comments args
//comment callback function
if ('' === $this->options->get('cgb_comment_adjust') && function_exists($this->options->get('cgb_comment_adjust'))) {
$args['callback'] = $this->options->get('cgb_comment_callback');
} else {
$args['callback'] = array(&$this, 'show_comment_html');
}
//correct order of top level comments
if ('default' !== $this->options->get('cgb_clist_order')) {
$args['reverse_top_level'] = false;
}
//correct order of child comments
if ('desc' === $this->options->get('cgb_clist_child_order')) {
$args['reverse_children'] = true;
} elseif ('asc' === $this->options->get('cgb_clist_child_order')) {
$args['reverse_children'] = false;
}
//change child order if top level order is desc due to array_reverse
if ('desc' === $this->options->get('cgb_clist_order')) {
$args['reverse_children'] = isset($args['reverse_children']) ? !$args['reverse_children'] : true;
}
// Print comments
wp_list_comments($args);
}
示例3: wpc_heartbeat_response
function wpc_heartbeat_response($response, $data)
{
if (isset($data['wpc_comment_update'])) {
global $wpdb;
//get the newest comment-timestamp:
// (we don't have to go to the DB for this every time, post_meta gets cached and updated only when the records get updated)
$last_commented = get_post_meta($data['wpc_comment_update']['post_id'], '_wpc_comment_timestamp', true);
//check the timestamp of our last known version versus the one in the heartbeat:
if ($data['wpc_comment_update']['timestamp'] != $last_commented) {
// We have data with our handle and a new comment! lets respond with something...
// Get comments from the old timestamp up and post_id = $data['post_id'];
$time = date('Y-m-d H:i:s', $last_commented);
$post_id = $data['wpc_comment_update']['post_id'];
//Query the new comments for this post that have been posted since:
$_comments = $wpdb->get_results($wpdb->prepare("\n\t \t\t\t\t\tSELECT * \n\t \t\t\t\t\tFROM {$wpdb->comments} \n\t \t\t\t\t\tWHERE comment_post_ID = {$post_id} \n\t \t\t\t\t\tAND comment_date >= '{$time}' \n\n\t \t\t\t\t "));
//Now, output the newest comments in html:
ob_start();
wp_list_comments(array('style' => 'ol', 'short_ping' => true, 'avatar_size' => 74), $_comments);
//get the output buffer and clean it:
$html = ob_get_clean();
//then add it to the response object we're sending back
//including the updated timestamp.
$response['wpc_comment_update'] = array('timestamp' => $last_commented, 'html' => $html);
}
}
return $response;
}
示例4: get_comments
public function get_comments()
{
if (isset($_GET['post'])) {
$comments = get_comments(array('post_id' => intval($_GET['post']), 'status' => 'approve'));
wp_list_comments(array('style' => 'ol', 'callback' => 'dwqa_question_comment_callback'), $comments);
}
exit(0);
}
示例5: show
public function show()
{
global $post;
if (post_password_required($post)) {
return;
}
echo '<ul class="commentlist">';
wp_list_comments(array("callback" => array(&$this, "format"), "walker" => new Walker_Comment_PE()));
echo '</ul>';
}
示例6: test_has_children
/**
* @ticket 14041
*/
function test_has_children()
{
$comment_parent = self::factory()->comment->create(array('comment_post_ID' => $this->post_id));
$comment_child = self::factory()->comment->create(array('comment_post_ID' => $this->post_id, 'comment_parent' => $comment_parent));
$comment_parent = get_comment($comment_parent);
$comment_child = get_comment($comment_child);
$comment_walker = new Walker_Comment();
$comment_callback = new Comment_Callback_Test($this, $comment_walker);
wp_list_comments(array('callback' => array($comment_callback, 'comment'), 'walker' => $comment_walker, 'echo' => false), array($comment_parent, $comment_child));
wp_list_comments(array('callback' => array($comment_callback, 'comment'), 'walker' => $comment_walker, 'echo' => false), array($comment_child, $comment_parent));
}
示例7: fruitframeLoadCommentsHook
/**
* Load Comments AJAX Hook
*/
public function fruitframeLoadCommentsHook()
{
$id = (int) $_POST['id'];
$query = new WP_Query(array('post_type' => 'post', 'p' => $id, 'post_status' => 'publish'));
while ($query->have_posts()) {
$query->the_post();
$comments = get_comments(array('post_id' => get_the_ID(), 'orderby' => 'comment_date_gmt', 'order' => 'ASC', 'status' => 'approve'));
wp_list_comments(array('callback' => 'fruitframe_comment'), $comments);
}
exit;
}
示例8: tc_comment_list
/**
* Comments Rendering
*
* @package Customizr
* @since Customizr 3.0
*/
function tc_comment_list()
{
?>
<ul class="commentlist">
<?php
wp_list_comments(array('callback' => array($this, 'tc_comment_callback'), 'style' => 'ul'));
?>
</ul><!-- .commentlist -->
<?php
}
示例9: cherry_comments_default_list
/**
* Dispaly the list of comments.
*
* @since 4.0.0
*/
function cherry_comments_default_list()
{
$defaults = array('style' => 'ol', 'type' => 'all', 'avatar_size' => 48, 'short_ping' => true, 'callback' => 'cherry_rewrite_comment_item');
/**
* Filter the defaults list arguments of comments.
*
* @since 4.0.0
* @param array $defaults Defaults arguments.
*/
$args = apply_filters('cherry_comment_list_args', $defaults);
// Set argument 'echo' to the function 'wp_list_comments' for return result.
$args = array_merge($args, array('echo' => false));
printf('<%1$s class="comment-list">%2$s</%1$s>', tag_escape($args['style']), wp_list_comments($args));
}
示例10: list_comments
/**
* List Comments
*
* @param TimberPost $post
* @global integer $cpage
* @global boolean $overridden_cpage
*/
function list_comments($post)
{
global $cpage, $overridden_cpage;
$cpage = $cpage ? $cpage : 1;
$overridden_cpage = true;
$commentsPerPage = (int) get_option('comments_per_page');
$commentsOrder = get_option('comment_order');
$defaultCommentsPage = get_option('default_comments_page');
$commentPage = $cpage;
$lastPage = ceil($post->comment_count / $commentsPerPage);
if ($defaultCommentsPage == 'newest') {
$commentPage = $lastPage - $cpage + 1;
}
wp_list_comments(array('callback' => 'render_comment'), get_comments(array('post_id' => $post->ID, 'number' => $commentsPerPage, 'offset' => (int) ($commentPage - 1) * $commentsPerPage, 'order' => $commentsOrder)));
}
示例11: novusopress_comments_list
function novusopress_comments_list(array $args = [], $echo = true)
{
$defaults = ['listEl' => 'ol', 'listId' => 'comment-list', 'listClass' => 'comment-list list-unstyled', 'callback' => 'novusopress_comment', 'endCallback' => 'novusopress_comment_end', 'indent' => 5, 'tab' => ' '];
$args = wp_parse_args($args, $defaults);
extract($args, EXTR_SKIP);
$tabs = str_repeat($tab, $indent);
$output = [];
$output[] = sprintf('%s<%s id="%s" class="%s">%s', $tabs, $listEl, $listId, $listClass, PHP_EOL);
$output[] = wp_list_comments(['callback' => $callback, 'end-callback' => $endCallback, 'walker' => new CommentWalker(), 'echo' => false]);
$output[] = sprintf('%s</%s><!-- #%s -->%s', $tabs, $listEl, $listId, PHP_EOL);
$output = apply_filters('novusopress_comments_list_output', implode('', $output));
if ($echo) {
echo $output;
} else {
return $output;
}
}
示例12: tc_comment_list
/**
* Comment list Rendering
*
* @package Customizr
* @since Customizr 3.0
*/
function tc_comment_list()
{
$_args = apply_filters('tc_list_comments_args', array('callback' => array($this, 'tc_comment_callback'), 'style' => 'ul'));
ob_start();
?>
<ul class="commentlist">
<?php
wp_list_comments($_args);
?>
</ul><!-- .commentlist -->
<?php
$html = ob_get_contents();
if ($html) {
ob_end_clean();
}
echo apply_filters('tc_comment_list', $html);
}
示例13: test_should_respect_reverse_top_level_param
/**
* @ticket 35175
*/
public function test_should_respect_reverse_top_level_param()
{
$p = self::factory()->post->create();
$comments = array();
$now = time();
for ($i = 0; $i <= 5; $i++) {
$comments[] = self::factory()->comment->create(array('comment_post_ID' => $p, 'comment_date_gmt' => date('Y-m-d H:i:s', $now - $i), 'comment_author' => 'Commenter ' . $i));
}
update_option('page_comments', true);
update_option('comments_per_page', 2);
$this->go_to(get_permalink($p));
// comments_template() populates $wp_query->comments
get_echo('comments_template');
$found1 = wp_list_comments(array('reverse_top_level' => true, 'echo' => false));
preg_match_all('|id="comment\\-([0-9]+)"|', $found1, $matches);
$this->assertSame(array($comments[0], $comments[1]), array_map('intval', $matches[1]));
$found2 = wp_list_comments(array('reverse_top_level' => false, 'echo' => false));
preg_match_all('|id="comment\\-([0-9]+)"|', $found2, $matches);
$this->assertSame(array($comments[1], $comments[0]), array_map('intval', $matches[1]));
}
示例14: supernova_theme_setup
function supernova_theme_setup()
{
global $background_defaults, $header_defaults, $wp_version;
//Featured image for both page and post
add_theme_support('post-thumbnails');
//Adds automatic feed links
add_theme_support('automatic-feed-links');
//Adds Custom background
add_theme_support('custom-background', $background_defaults);
//Adds Custom Header
add_theme_support('custom-header', $header_defaults);
add_theme_support("title-tag");
//Setting Avatar Size
wp_list_comments('avatar_size=80');
// Visual Editor Style
add_editor_style();
//Loading Language File
load_theme_textdomain('Supernova', SUPERNOVA_DIR . '/languages');
//Navigation Registration
register_nav_menus(array('Header_Nav' => __('Header Navigation', 'Supernova'), 'Header_Cat' => __('Header Categories', 'Supernova'), 'Main_Nav' => __('Main Navigation', 'Supernova'), 'Footer_Nav' => __('Footer Navigation', 'Supernova')));
do_action('supernova_after_theme_setup');
}
示例15: miss_comment_list
/**
*
*/
function miss_comment_list()
{
//echo apply_filters( 'miss_comments_title', '<h3 id="comments-title">' . sprintf( _n( '1 Comment', '%1$s Comments', get_comments_number(), MISS_TEXTDOMAIN ), number_format_i18n( get_comments_number() ), get_the_title() ) . '</h3>', array( 'comments_number' => get_comments_number(), 'title' => get_the_title() ) );
?>
<div class="comments">
<?php
wp_list_comments(array('type' => 'all', 'walker' => new zipGun_walker_comment()));
?>
</div>
<?php
if (get_option('page_comments')) {
?>
<div class="comment-navigation paged-navigation">
<?php
paginate_comments_links(miss_portfolio_comment_url($nav = true));
?>
</div><!-- .comment-navigation -->
<?php
}
?>
<?php
}