有很多关于如何在WP中设置“autor”或“admin”注释样式的文档,但大多数文档似乎已经过时了。
我有一位客户,我正在为他开发问答;一个站点。我一直认为最好使用Wordpress已经提供给我的任何工具。这就是为什么我决定建立一个表单,将所有“问题”推送到一个自定义的帖子类型。然后我的客户可以阅读和评论他的答案。
我遇到的唯一问题是,我需要用几种方式来表达他的评论。他们需要脱颖而出。这很容易实现,因为WP现在为每个作者的评论动态生成一个类。所以我写了一些CSS:
.comment-author-myClient {
background-color: #bcd1f7;
padding: 10px;
border: 1px dotted black;
}
这让他的评论看起来与众不同。但这还不够。我真的很想编辑他的特定评论模板。而不是像“用户说:”我希望它说“我的客户的答案:”
我还希望他的评论永远保持在首位。
现在,这不应该成为一个问题,因为标准WP注释是以ASC格式显示的,所以只要是第一个注释(他应该始终是),他的注释应该始终位于顶部。但是,我只想安全。
此外,我希望他的评论出现在:
X对“帖子标题”的回复:
只是为了让每一个想帮助我的人都能轻松地。。以下是二十条评论。php文件:
<?php
/**
* The template for displaying Comments.
*
* The area of the page that contains both current comments
* and the comment form. The actual display of comments is
* handled by a callback to twentyten_comment which is
* located in the functions.php file.
*
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.0
*/
?>
<div id="comments">
<?php if ( post_password_required() ) : ?>
<p class="nopassword"><?php _e( \'This post is password protected. Enter the password to view any comments.\', \'twentyten\' ); ?></p>
</div><!-- #comments -->
<?php
/* Stop the rest of comments.php from being processed,
* but don\'t kill the script entirely -- we still have
* to fully load the template.
*/
return;
endif;
?>
<?php
// You can start editing here -- including this comment!
?>
<?php if ( have_comments() ) : ?>
<h3 id="comments-title"><?php
printf( _n( \'One Response to %2$s\', \'%1$s Responses to %2$s\', get_comments_number(), \'twentyten\' ),
number_format_i18n( get_comments_number() ), \'<em>\' . get_the_title() . \'</em>\' );
?></h3>
<?php if ( get_comment_pages_count() > 1 && get_option( \'page_comments\' ) ) : // Are there comments to navigate through? ?>
<div class="navigation">
<div class="nav-previous"><?php previous_comments_link( __( \'<span class="meta-nav">←</span> Older Comments\', \'twentyten\' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( __( \'Newer Comments <span class="meta-nav">→</span>\', \'twentyten\' ) ); ?></div>
</div> <!-- .navigation -->
<?php endif; // check for comment navigation ?>
<ol class="commentlist">
<?php
/* Loop through and list the comments. Tell wp_list_comments()
* to use twentyten_comment() to format the comments.
* If you want to overload this in a child theme then you can
* define twentyten_comment() and that will be used instead.
* See twentyten_comment() in twentyten/functions.php for more.
*/
wp_list_comments( array( \'callback\' => \'twentyten_comment\' ) );
?>
</ol>
<?php if ( get_comment_pages_count() > 1 && get_option( \'page_comments\' ) ) : // Are there comments to navigate through? ?>
<div class="navigation">
<div class="nav-previous"><?php previous_comments_link( __( \'<span class="meta-nav">←</span> Older Comments\', \'twentyten\' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( __( \'Newer Comments <span class="meta-nav">→</span>\', \'twentyten\' ) ); ?></div>
</div><!-- .navigation -->
<?php endif; // check for comment navigation ?>
<?php else : // or, if we don\'t have comments:
/* If there are no comments and comments are closed,
* let\'s leave a little note, shall we?
*/
if ( ! comments_open() ) :
?>
<p class="nocomments"><?php _e( \'Comments are closed.\', \'twentyten\' ); ?></p>
<?php endif; // end ! comments_open() ?>
<?php endif; // end have_comments() ?>
<?php comment_form(); ?>
</div><!-- #comments -->
这是函数的一部分。它所指的php:
if ( ! function_exists( \'twentyten_comment\' ) ) :
/**
* Template for comments and pingbacks.
*
* To override this walker in a child theme without modifying the comments template
* simply create your own twentyten_comment(), and that function will be used instead.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*
* @since Twenty Ten 1.0
*/
function twentyten_comment( $comment, $args, $depth ) {
$GLOBALS[\'comment\'] = $comment;
switch ( $comment->comment_type ) :
case \'\' :
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-author vcard">
<?php echo get_avatar( $comment, 40 ); ?>
<?php printf( __( \'%s <span class="says">says:</span>\', \'twentyten\' ), sprintf( \'<cite class="fn">%s</cite>\', get_comment_author_link() ) ); ?>
</div><!-- .comment-author .vcard -->
<?php if ( $comment->comment_approved == \'0\' ) : ?>
<em class="comment-awaiting-moderation"><?php _e( \'Your comment is awaiting moderation.\', \'twentyten\' ); ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
<?php
/* translators: 1: date, 2: time */
printf( __( \'%1$s at %2$s\', \'twentyten\' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( \'(Edit)\', \'twentyten\' ), \' \' );
?>
</div><!-- .comment-meta .commentmetadata -->
<div class="comment-body"><?php comment_text(); ?></div>
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( \'depth\' => $depth, \'max_depth\' => $args[\'max_depth\'] ) ) ); ?>
</div><!-- .reply -->
</div><!-- #comment-## -->
<?php
break;
case \'pingback\' :
case \'trackback\' :
?>
<li class="post pingback">
<p><?php _e( \'Pingback:\', \'twentyten\' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( \'(Edit)\', \'twentyten\' ), \' \' ); ?></p>
<?php
break;
endswitch;
}
endif;
到目前为止,我找到的关于修改管理员注释的所有文档都来自WP和Twentyten的早期版本,其中注释循环都存储在注释中。php,并且具有非常不同的格式。因此,对于我在这里努力实现的目标的任何帮助,我都将非常非常感激。
TIA公司
SO网友:Lynne
我确实弄明白了。尽管可能有更干净的方法。我不知道。。这是我的新功能。php文件。。。
<?php /* If the author is myclient, use class \'author\' otherwise, use class \'comment byuser\' */
if ($comment->comment_author_email == "[email protected]")
echo \'<li class="author">\';
else
echo \'<li class="comment byuser">\';
/* I had to make this li class static because I don\'t know how
to inject PHP in an echo that\'s in an if/else statement.
echo \'stuff here\' . php here . \'more stuff\'; did not work.
*/
?>
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-author vcard">
<?php /* get user avatar only if the author is NOT myClient */
if ($comment->comment_author_email !== "[email protected]")
echo get_avatar( $comment, 40 );
?>
<?php if /* if the user is myClient, append "myClient answers" instead of the author link. Otherwise, proceed as normal. */
($comment->comment_author_email == "[email protected]")
printf( __( \'<b>myClient Answers:</b>\', \'twentyten\' ), sprintf( \'<cite class="fn">%s</cite>\', get_comment_author_link() ) );
else
printf( __( \'%s <span class="says">replies:</span>\', \'twentyten\' ), sprintf( \'<cite class="fn">%s</cite>\', get_comment_author_link() ) );
?>
</div><!-- .comment-author .vcard -->
<?php if ( $comment->comment_approved == \'0\' ) : ?>
<em class="comment-awaiting-moderation"><?php _e( \'Your comment is awaiting moderation.\', \'twentyten\' ); ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
<?php
/* translators: 1: date, 2: time */
printf( __( \'%1$s at %2$s\', \'twentyten\' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( \'(Edit)\', \'twentyten\' ), \' \' );
?>
</div><!-- .comment-meta .commentmetadata -->
<div class="comment-body"><?php comment_text(); ?></div>
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( \'depth\' => $depth, \'max_depth\' => $args[\'max_depth\'] ) ) ); ?>
</div><!-- .reply -->
</div><!-- #comment-## -->
</li>
<?php if /* if the comment is by myClient, append this div after it. */($comment->comment_author_email == "[email protected]")
echo \'<div id="commentdivider"></div>\';
echo \'<br>\';
?>
<?php
break;
case \'pingback\' :
case \'trackback\' :
?>
<li class="post pingback">
<p><?php _e( \'Pingback:\', \'twentyten\' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( \'(Edit)\', \'twentyten\' ), \' \' ); ?></p>
</li>
<?php
break;
endswitch;
}
endif;
然后,您只需为分配给管理员注释的类设置样式,如下所示。。。。
.author {
line-height: 24px;
padding: 20px;
position: relative;
background-color: #EDEFF4;
margin-bottom: 25px;
}
您还可以对其他注释进行一些调整,使其看起来更漂亮。我只是稍微改变了边距和填充。以下是成品的屏幕截图:
我只是把“对帖子标题的x回应”完全排除在外。