<?php
if ( post_password_required() ) { ?>
<p>This post is password protected. Enter the password to view comments.</p>
<?php
return;
}
if( have_comments() ) : ?>
<h5 class="cufon"><?php comments_number('No comment', 'Comment', '% Comments'); ?> for <?php the_title(); ?></h5><br/>
<?php wp_list_comments( array('callback' => 'pp_comment', 'avatar_size' => '40') ); ?>
<!-- End of thread -->
<br class="clear"/><br/>
<?php endif; ?>
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?>
<div class="pagination"><p><?php previous_comments_link(); ?> <?php next_comments_link(); ?></p></div><br class="clear"/><div class="line"></div><br/><br/>
<?php endif; // check for comment navigation ?>
<?php if ('open' == $post->comment_status) : ?>
<div id="respond">
<?php include(TEMPLATEPATH . '/templates/comments-form.php'); ?>
</div>
<?php endif; ?>
wordpress小技巧:如何在首页显示最新评论
可以利用wordpress中的widgets来搞定,来吧实战开始:
首先,备份\wp-includes\default-widgets.php
然后,找到\wp-includes\default-widgets.php文件中,大约在679行
sprintf(_x('%1$son%2$s','widgets'),get_comment_author_link(),'<ahref="'.esc_url(get_comment_link($comment->comment_ID)).'">'.get_the_title($comment->comment_post_ID).'</a>').'</li>';
将其修改为:
//sprintf(_x('%1$son%2$s','widgets'),get_comment_author_link(),'<ahref="'.esc_url(//get_comment_link($comment->comment_ID)).'">'.get_the_title($comment->comment_post_ID).'</a>').'</li>';
sprintf(_x('%1$s在“%2$s”留言:','widgets'),get_comment_author_link(),'<ahref="'.esc_url(
get_comment_link($comment->comment_ID)).'">'.get_the_title($comment->comment_post_ID).'</a>').'<span>'.strip_tags($comment->comment_content).'</span></li>';
这样就OK了。
前台显示效果如图:
wordpress修改评论
用下面这段代码代替你原来的代码
<?php comment_form(array('comment_notes_after' => '','fields' => apply_filters( 'comment_form_default_fields', array(
'author' =>
'<p class="comment-form-author">' .
'<label for="author">' . __( '姓名', 'domainreference' ) . '</label> ' .
( $req ? '<span class="required">*</span>' : '' ) .
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .
'" size="30"' . $aria_req . ' /></p>',)),'comment_notes_before' => '','comment_field' => '<p class="comment-form-comment"><textarea id="comment" name="comment" cols="90" rows="8" aria-required="true">' .
'</textarea></p>',)); ?>
看到有许多朋友提到“WordPress文章ID不连续”怎么办
WordPress
先判断下是否登录,然后获取当前用户对象,然后获取当前用户对象的信息,需要哪些用哪些:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
if(is_user_logged_in()){
$current_user = wp_get_current_user();
/**
* @example Safe usage: $current_user = wp_get_current_user();
* if ( !($current_user instanceof WP_User) )
* return;
*/
echo 'Username: ' . $current_user->user_login . '<br />';
echo 'User email: ' . $current_user->user_email . '<br />';
echo 'User first name: ' . $current_user->user_firstname . '<br />';
echo 'User last name: ' . $current_user->user_lastname . '<br />';
echo 'User display name: ' . $current_user->display_name . '<br />';
echo 'User ID: ' . $current_user->ID . '<br />';
}
wordpress文章为什么id不是按顺序的?
因为wordpress为了避免用户在编辑文章的过程中断线等原因造成数据丢失,有个自动保存功能,每次自动保存的时候都会生成一个ID。所以就造成了文章ID不连续
谢谢 我知道了
wordpress 如何获得所有评论者邮箱
代码如下:
add_action('admin_init','coolwp_get_emails_of_commentators1');
functioncoolwp_get_emails_of_commentators1(){
$emails=coolwp_get_emails_of_commentators();
var_dump($emails);
}
/*
以上为测试使用
*/
/**
*[coolwp_get_emails_of_commentatorsdescription]
*@returnarray|false成功则返回一个数组(评论者的用户ID为键名,邮箱为键值),不成功返回布尔值false
*@authorsuifengteccoolwp.com
*/
functioncoolwp_get_emails_of_commentators(){
global$wpdb;
/*
1=1
`comment_approved`=1
*/
$where="1=1";
$sql="SELECT`user_id`FROM`{$wpdb->prefix}comments`WHERE{$where}GROUPBY`user_id`";
$commentator_ids=$wpdb->get_results($sql,ARRAY_A);
$emails=array();
foreach($commentator_idsas$commentator_id){
$email=false;
$email=coolwp_get_user_email($commentator_id['user_id'])?coolwp_get_user_email($commentator_id['user_id']):false;
if(!$email){
$email=false;
continue;
}
$emails[$commentator_id['user_id']]=$email;
}
returnis_array($emails)?$emails:false;
}
/**
*[coolwp_get_user_emaildescription]
*@paramstring|int$user_id用户ID
*@returnstring|false[description]
*@authorsuifengteccoolwp.com
*/
functioncoolwp_get_user_email($user_id){
if(empty($user_id)||!$user_id)returnfalse;
$user_id=intval($user_id);
global$wpdb;
$sql="SELECT`user_email`FROM{$wpdb->prefix}usersWHERE`ID`={$user_id}";
$email=$wpdb->get_var($sql);
return$email?$email:false;
}
改进:
/***功能同上,更简洁高效些
*@return[type][description]
*@authorsuifengteccoolwp.com
*/
functioncoolwp_get_emails_of_commentators2(){
global$wpdb;
$where="1=1";
$sql="SELECT`user_email`
FROM{$wpdb->prefix}users
LEFTJOIN`{$wpdb->prefix}comments`
ON{$wpdb->prefix}comments.user_id={$wpdb->prefix}users.ID
WHERE{$where}
GROUPBY{$wpdb->prefix}comments.user_id";
$emails=$wpdb->get_results($sql,ARRAY_A);
returnis_array($emails)?$emails:false;
}
祝愉快!
转载请注明出处51数据库 » wordpress评论id wordpress评论代码求助
爱42774197
