本文整理汇总了PHP中get_comments函数的典型用法代码示例。如果您正苦于以下问题:PHP get_comments函数的具体用法?PHP get_comments怎么用?PHP get_comments使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_comments函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: alaya_recent_comment
function alaya_recent_comment($number)
{
$commentNum = 1;
// Get the comments
$recent_comments = get_comments(array('number' => $number, 'status' => 'approve', 'type' => 'comment'));
$commentList = '<ul>';
foreach ($recent_comments as $comment) {
$commentList .= '<li>
<header class="clearfix">
<figure>
<a href="' . get_permalink($comment->comment_post_ID) . '">
' . get_avatar($comment->comment_author_email, '40') . '
</a>
<span class="comment-author-name">
' . $comment->comment_author . '
</span>
<div class="comment-order">' . $commentNum . '</div>
</figure>
<a class="comment-post" href="' . esc_url(get_permalink($comment->comment_post_ID)) . '#comment-' . esc_attr($comment->comment_ID) . '">
' . esc_attr(get_the_title($comment->comment_post_ID)) . '
</a>
</header>
<div class="comment-text">
<div class="up-arrow"></div>
' . wp_trim_words($comment->comment_content, 30) . '
</div>
</li>';
$commentNum++;
}
$commentList .= '</ul>';
return $commentList;
}
示例2: process_refund
/**
* Process a refund if supported
* @param int $order_id
* @param float $amount
* @param string $reason
* @return bool|wp_error True or false based on success, or a WP_Error object
*/
public function process_refund($order_id, $amount = null, $reason = '')
{
$order = wc_get_order($order_id);
$transaction_id = null;
$args = array('post_id' => $order->id, 'approve' => 'approve', 'type' => '');
remove_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'));
$comments = get_comments($args);
foreach ($comments as $comment) {
if (strpos($comment->comment_content, 'Transaction ID: ') !== false) {
$exploded_comment = explode(": ", $comment->comment_content);
$transaction_id = $exploded_comment[1];
}
}
add_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'));
if (!$order || !$transaction_id) {
return false;
}
// Add transaction-specific details to the request
$transaction_details = array('username' => $this->username, 'password' => $this->password, 'type' => 'refund', 'transactionid' => $transaction_id, 'ipaddress' => $_SERVER['REMOTE_ADDR']);
if (!is_null($amount)) {
$transaction_details['amount'] = number_format($amount, 2, '.', '');
}
// Send request and get response from server
$response = $this->post_and_get_response($transaction_details);
// Check response
if ($response['response'] == 1) {
// Success
$order->add_order_note(__('Inspire Commerce refund completed. Refund Transaction ID: ', 'woocommerce') . $response['transactionid']);
return true;
} else {
// Failure
$order->add_order_note(__('Inspire Commerce refund error. Response data: ', 'woocommerce') . http_build_query($response));
return false;
}
}
示例3: siiimple_comments
function siiimple_comments($args)
{
extract($args, EXTR_SKIP);
echo $before_widget . "\n";
echo $before_title . 'Recent Comments' . $after_title . "\n";
$comments = get_comments('status=approve&number=5');
if ($comments) {
echo '<ul id="recent_comments">';
foreach ($comments as $comment) {
echo '<li><a href="' . get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '" title="' . $comment->comment_author . ' | ' . get_the_title($comment->comment_post_ID) . '">' . get_avatar($comment->comment_author_email, $img_w);
echo '<span class="recent_comment_name">' . $comment->comment_author . '</span><br/>';
$comment_string = $comment->comment_content;
$comment_excerpt = substr($comment_string, 0, 20);
echo $comment_excerpt;
if (strlen($comment_excerpt) > 25) {
echo ' ...';
}
echo '</a></li>';
}
echo '</ul>';
} else {
echo '<ul id="recent_comments">
<li>No Comments Yet</li>
</ul>';
}
echo $after_widget . "\n";
}
示例4: the_content
/**
* Add the reaction buttons to the post content.
* @param string $content The content HTML
* @return string The content HTML, with the react buttons attached
*/
public function the_content($content)
{
$post_id = get_the_ID();
if (!$post_id) {
return $content;
}
$reactions = get_comments(array('post_id' => $post_id, 'type' => 'reaction'));
$reactions_summary = array();
foreach ($reactions as $reaction) {
if (!isset($reactions_summary[$reaction->comment_content])) {
$reactions_summary[$reaction->comment_content] = 0;
}
$reactions_summary[$reaction->comment_content]++;
}
$content .= '<div class="emoji-reactions">';
foreach ($reactions_summary as $emoji => $count) {
$content .= "<div data-emoji='{$emoji}' data-count='{$count}' data-post='{$post_id}' class='emoji-reaction'><div class='emoji'>{$emoji}</div><div class='count'>{$count}</div></div>";
}
if (comments_open($post_id)) {
/* translators: This is the emoji used for the "Add new emoji reaction" button */
$content .= "<div data-post='{$post_id}' class='emoji-reaction-add'><div class='emoji'>" . __('😃+', 'react') . '</div></div>';
}
$content .= '</div>';
return $content;
}
示例5: wp_count_comments_override
function wp_count_comments_override($comments, $post_id = 0)
{
add_filter('comments_clauses', array('CommentsInterceptor_RS', 'wp_count_comments_clauses'), 99, 2);
$count = get_comments(array('post_id' => $post_id));
remove_filter('comments_clauses', array('CommentsInterceptor_RS', 'wp_count_comments_clauses'), 99, 2);
// remainder of this function ported from WP 3.2 function wp_count_comments()
$total = 0;
$approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed');
foreach ((array) $count as $row) {
$row = (array) $row;
// RS modification
// Don't count post-trashed toward totals
if ('post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved']) {
$total += $row['num_comments'];
}
if (isset($approved[$row['comment_approved']])) {
$stats[$approved[$row['comment_approved']]] = $row['num_comments'];
}
}
$stats['total_comments'] = $total;
foreach ($approved as $key) {
if (empty($stats[$key])) {
$stats[$key] = 0;
}
}
$stats = (object) $stats;
return $stats;
}
示例6: get
/**
* Query the database for specific liveblog entries
*
* @param array $args the same args for the core `get_comments()`.
* @return array array of `WPCOM_Liveblog_Entry` objects with the found entries
*/
private function get($args = array())
{
$defaults = array('post_id' => $this->post_id, 'orderby' => 'comment_date_gmt', 'order' => 'DESC', 'type' => $this->key, 'status' => $this->key);
$args = wp_parse_args($args, $defaults);
$comments = get_comments($args);
return self::entries_from_comments($comments);
}
示例7: widget
/**
* widget function.
*
* @see WP_Widget
* @access public
* @param array $args
* @param array $instance
* @return void
*/
public function widget($args, $instance)
{
global $comments, $comment, $woocommerce;
if ($this->get_cached_widget($args)) {
return;
}
ob_start();
extract($args);
$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
$number = absint($instance['number']);
$comments = get_comments(array('number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product'));
if ($comments) {
echo $before_widget;
if ($title) {
echo $before_title . $title . $after_title;
}
echo '<ul class="product_list_widget">';
foreach ((array) $comments as $comment) {
$_product = get_product($comment->comment_post_ID);
$rating = intval(get_comment_meta($comment->comment_ID, 'rating', true));
$rating_html = $_product->get_rating_html($rating);
echo '<li><a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">';
echo $_product->get_image();
echo $_product->get_title() . '</a>';
echo $rating_html;
printf('<span class="reviewer">' . _x('by %1$s', 'by comment author', 'woocommerce') . '</span>', get_comment_author());
echo '</li>';
}
echo '</ul>';
echo $after_widget;
}
$content = ob_get_clean();
echo $content;
$this->cache_widget($args, $content);
}
示例8: getWordpressData
static function getWordpressData() {
/**
* Get all global page data
*/
$blogDataParams = array(
'url', 'wpurl', 'description', 'rdf_url' , 'rss_url', 'rss2_url'
, 'atom_url', 'comments_atom_url', 'comments_rss2_url', 'pingback_url'
, 'stylesheet_url', 'stylesheet_directory', 'template_directory'
, 'template_url', 'admin_email', 'charset', 'html_type', 'version'
, 'language', 'text_direction', 'name'
);
$blogData = array();
foreach($blogDataParams as $blogDataParam) {
$blogData[self::toCamelCase($blogDataParam)] = get_bloginfo($blogDataParam);
}
$blogData = array_merge($blogData, array(
'title' => wp_title(' | ', false, 'right') . get_bloginfo('name'),
'archiveLinksHTML' => wp_get_archives('type=monthly&limit=5&format=link&echo=0'),
'bodyClasses' => self::getEchoFunctionContents('body_class'),
'posts' => array()
));
/**
* Get posts data
*/
while (have_posts()) {
the_post();
$postId = get_the_ID();
// Get category data
$categories = get_the_category();
$categoryNames = array();
foreach($categories as $category) {
array_push($categoryNames, $category->cat_name);
}
// Add all relevant post data to the posts array
array_push(
$blogData['posts'],
array_merge(
get_object_vars(get_post($postId)),
array(
'classes' => get_post_class(),
'comments' => get_comments(array('post_id' => $postId)),
'custom' => get_post_custom(),
'permalink' => get_permalink(),
'categories' => $categories,
'categoryNames' => $categoryNames,
'categoriesStr' => implode(',', $categoryNames)
)
)
);
}
return $blogData;
}
示例9: get_most_recent_comments
function get_most_recent_comments($args = null)
{
global $most_recent_comments_args;
// You can pass any of these arguments as well as any argument supported by get_comments()
$defaults = array('passworded_posts' => false, 'showpings' => false, 'post_types' => array('post', 'page'), 'post_statuses' => array('publish', 'static'), 'number' => 5, 'status' => 'approve');
$most_recent_comments_args = wp_parse_args($args, $defaults);
// Create the cache key
$key = md5(serialize($most_recent_comments_args));
$last_changed = wp_cache_get('last_changed', 'comment');
if (!$last_changed) {
$last_changed = time();
wp_cache_set('last_changed', $last_changed, 'comment');
}
$cache_key = "most_recent_comments:{$key}:{$last_changed}";
// Check to see if we already have results for this request
if ($cache = wp_cache_get($cache_key, 'comment')) {
return $cache;
}
// Modify the get_comments() SQL query
add_filter('comments_clauses', '_mrc_modify_comments_clauses');
// Get the comments
// The custom arguments will be ignored by get_comments()
$comments = get_comments($most_recent_comments_args);
// Remove the get_comments() SQL query filter
remove_filter('comments_clauses', '_mrc_modify_comments_clauses');
// Cache these results
wp_cache_add($cache_key, $comments, 'comment');
return $comments;
}
示例10: show_comments_page
function show_comments_page($dbconn, $diary_login)
{
$nid = (int) $_GET['nid'];
// Get Note
$sql = "SELECT u.uid, n.* FROM " . TABLE_USERS . " AS u, " . TABLE_NOTES . " AS n WHERE u.login='" . $diary_login . "' AND n.uid=u.uid AND n.nid='" . $nid . "' LIMIT 1";
$result = pg_query($sql) or die(pg_last_error($dbconn));
if (pg_num_rows($result) == 0) {
show_error_page($dbconn, $diary_login, "no such note!");
return;
} else {
$datanote = pg_fetch_object($result, NULL);
pg_free_result($result);
$sql = "SELECT u.uid, s.format_note, s.page_comments, s.format_comment FROM " . TABLE_SETTINGS . " AS s, " . TABLE_USERS . " AS u WHERE u.login='" . $diary_login . "' AND s.uid=u.uid LIMIT 1";
$result = pg_query($sql) or die(pg_last_error($dbconn));
$dataformat = pg_fetch_object($result, NULL);
// Strip link to add comment and number of comments
$dataformat->format_note = preg_replace('/(<a.* href="{hrefcomment}")(.+)(.*>)/', '', $dataformat->format_note);
$dataformat->format_note = preg_replace('/(.?{commentscount}.?)/', '', $dataformat->format_note);
$note = assign_vars($dataformat->format_note, array('{subject}' => $datanote->subject, '{contents}' => $datanote->contents, '{date}' => date("d-m-Y", $datanote->timestamp), '{time}' => date("H:i:s", $datanote->timestamp)));
$comments = get_comments($dbconn, $diary_login, $dataformat->format_comment, $nid);
$sql = "SELECT COUNT(c.*) AS commentscount FROM " . TABLE_USERS . " AS u, " . TABLE_COMMENTS . " AS c WHERE c.nid='" . $nid . "' AND c.uid=u.uid AND u.login='" . $diary_login . "'";
$result = pg_query($sql) or die(pg_last_error($dbconn));
$datacount = pg_fetch_object($result, NULL);
pg_free_result($result);
$commentscount = (int) $datacount->commentscount;
echo assign_vars($dataformat->page_comments, array('{login}' => $diary_login, '{note}' => $note, '{comments}' => $comments, '{commentscount}' => $commentscount, '{hrefcommentadd}' => 'http://' . $_SERVER['SERVER_NAME'] . '/' . PAGE_COMMENTS . '&nid=' . $nid . '&action=add'));
}
}
示例11: anno_internal_comments_get_comments
/**
* Get a list of comments for a given type
*
* @param string $type Type of comments to fetch
* @return array Array of comment objects
*/
function anno_internal_comments_get_comments($type, $post_id)
{
remove_filter('comments_clauses', 'anno_internal_comments_clauses');
$comments = get_comments(array('type' => $type, 'post_id' => $post_id));
add_filter('comments_clauses', 'anno_internal_comments_clauses');
return $comments;
}
示例12: gen_comment_msg
function gen_comment_msg($t, $id)
{
$comments = get_comments($t, $id);
$msg = html_of_speaker($id) . "\n";
$msg .= html_of_comments($comments) . "\n";
return $msg;
}
示例13: widget_lmee_by_talk
function widget_lmee_by_talk($args)
{
extract($args);
echo $before_widget;
$lmee_popular_options = get_option('widget_lmee_popular');
$title = '灌水区-这里很热闹';
//设置默认的标题
echo $before_title . $title . $after_title;
$page_ID = 789;
//用来作为公告栏的页面或者文章id
$num = 5;
//显示公告的条数
echo '<ul class="by_talk">';
$announcement = '';
$comments = get_comments("number={$num}&post_id={$page_ID}");
if (!empty($comments)) {
$flg = 1;
foreach ($comments as $comment) {
if ($flg == 1) {
$li_title = $comment->comment_content;
if (similar_text($li_title, "<") > 0) {
//echo "is";
$start = stripos($li_title, "<");
//从前往后查找
$__li_title = strrev($li_title);
//反转字符串
$length = strlen($li_title) - $start - stripos($__li_title, ">");
$_li_title = substr_replace($li_title, "含引用", $start, $length);
$_li_html = substr_replace($li_title, "", $start, $length);
$announcement .= '<li class="by-talk-first"><a href="' . get_page_link($page_ID) . '#comment-' . $comment->comment_ID . '" title="' . $_li_title . '" rel="nofollow" target="_blank">' . $_li_html . '</a><br /><span style="color:#999;text-align:right;">(' . get_comment_date('Y/m/d H:i', $comment->comment_ID) . ')</span></li><hr />';
} else {
//echo "un";
$announcement .= '<li class="by-talk-first"><a href="' . get_page_link($page_ID) . '#comment-' . $comment->comment_ID . '" title="' . $li_title . '" rel="nofollow" target="_blank">' . convert_smilies($comment->comment_content) . '</a><br /><span style="color:#999;text-align:right;">(' . get_comment_date('Y/m/d H:i', $comment->comment_ID) . ')</span></li><hr />';
}
$flg++;
} else {
$li_title = $comment->comment_content;
if (similar_text($li_title, "<") > 0) {
//echo "is";
$start = stripos($li_title, "<");
//从前往后查找
$__li_title = strrev($li_title);
//反转字符串
$length = strlen($li_title) - $start - stripos($__li_title, ">");
$_li_title = substr_replace($li_title, "含引用", $start, $length);
$_li_html = substr_replace($li_title, "", $start, $length);
$announcement .= '<li><a href="' . get_page_link($page_ID) . '#comment-' . $comment->comment_ID . '" title="' . $_li_title . '" rel="nofollow" target="_blank">' . $_li_html . '</a><br /><span style="color:#999;text-align:right;">(' . get_comment_date('Y/m/d H:i', $comment->comment_ID) . ')</span></li><hr />';
} else {
//echo "un";
$announcement .= '<li><a href="' . get_page_link($page_ID) . '#comment-' . $comment->comment_ID . '" title="' . $li_title . '" rel="nofollow" target="_blank">' . convert_smilies($comment->comment_content) . '</a><br /><span style="color:#999;text-align:right;">(' . get_comment_date('Y/m/d H:i', $comment->comment_ID) . ')</span></li><hr />';
}
}
}
}
//if ( empty($announcement) ) $announcement = '<li>还没有人灌水奥!</li>';
echo $announcement;
echo '</ul>';
echo "<p style='text-align:right;'>[<a href='" . get_page_link($page_ID) . "#respond' rel='nofollow'>说两句</a>]</p>";
echo $after_widget;
}
示例14: widget
/**
* Outputs the content for the current Recent Comments widget instance.
*
* @param array $args Display arguments including 'before_title', 'after_title',
* 'before_widget', and 'after_widget'.
* @param array $instance Settings for the current Recent Comments widget instance.
*/
public function widget($args, $instance)
{
if (!isset($args['widget_id'])) {
$args['widget_id'] = $this->id;
}
$title = !empty($instance['title']) ? $instance['title'] : __('Recent Comments');
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
$title = apply_filters('widget_title', $title, $instance, $this->id_base);
$number = !empty($instance['number']) ? absint($instance['number']) : 5;
if (!$number) {
$number = 5;
}
$show_date = isset($instance['show_date']) ? $instance['show_date'] : false;
/**
* Filter the arguments for the Recent Comments widget.
*
* @since 3.4.0
*
* @see WP_Comment_Query::query() for information on accepted arguments.
*
* @param array $comment_args An array of arguments used to retrieve the recent comments.
*/
$comments = get_comments(apply_filters('widget_comments_args', array('number' => $number, 'status' => 'approve', 'post_status' => 'publish')));
if (is_array($comments) && $comments) {
// Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
$post_ids = array_unique(wp_list_pluck($comments, 'comment_post_ID'));
_prime_post_caches($post_ids, strpos(get_option('permalink_structure'), '%category%'), false);
$args['title'] = $title;
$args['comments'] = $comments;
$args['show_date'] = $show_date;
get_template_part_hierarchical_fetch('partials/widgets/recent-comments', '', $args);
wp_reset_postdata();
}
}
示例15: findByParentId
/**
* Find all comments by a given post ID
*
* @access public
* @param int $commentId
* @link http://codex.wordpress.org/Function_Reference/get_comments
* @return array
*/
public function findByParentId($commentId)
{
$args = array('parent' => $commentId);
$comments = get_comments($args);
// Convert and return the comments
return $this->convertAndReturn($comments);
}