php Wordpress自定义注释循环和注释表单

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Wordpress自定义注释循环和注释表单相关的知识,希望对你有一定的参考价值。

//-------------------------------------------------
//  Custom Comment Loop
//-------------------------------------------------

function custom_cmmt_loop($comment, $args, $depth) {
   $GLOBALS['comment'] = $comment; ?>
   <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
    <div id="comment-<?php comment_ID(); ?>">
      <div class="avatar">
          <?php echo get_avatar( $comment->comment_author_email, $img_w);?>
      </div>
      <div class="comment-main group">
        <div class="comment-meta">
          <?php printf(__('<cite class="fn">%s</cite>'), get_comment_author_link()); ?>
          <span class="comment-date">
            <!-- <a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"> -->
              <?php printf(__('%1$s'), get_comment_date()) ?>
            <!-- </a> -->
          </span>
        </div>

        <div class="comment-body">
          <?php if ($comment->comment_approved == '0') : ?>
            <em class="awaiting-moderation"><?php _e('Your comment is awaiting moderation.'); ?></em>
          <?php endif; ?>

          <?php comment_text(); ?> 
        </div>
        <div class="reply">
          <?php comment_reply_link(array_merge($args, array('depth' => $depth,
          'max_depth' => $args['max_depth']))); ?>
          <?php edit_comment_link(__('Edit'),'  ','') ?>
        </div>
      </div>
     
    </div>
<?php }

/* 
** Code from:
** Diggin' Into Wordpress
*/


//-------------------------------------------------
//  Custom Comment Form
//-------------------------------------------------

/* **************************************************** */
/* Customize the comment form textarea                  */
/* **************************************************** */
function wpsites_customize_comment_form_text_area($arg) {
    // removes label and addes placeholder to comment field
    $arg['comment_field'] = '<p class="comment-form-comment"><textarea id="comment-box" name="comment" placeholder="Your comment here..." aria-required="true"></textarea></p>';
    return $arg;
}
add_filter('comment_form_defaults', 'wpsites_customize_comment_form_text_area');
/* 
** Code from:
** http://wpsites.net/web-design/customize-comment-field-text-area-label/
*/

/* **************************************************** */
/* Customize the other input fields (name, email, etc.) */
/* **************************************************** */
function wpsites_modify_comment_form_fields($fields){
  
  // removes label & adds placeholder to author field.  
  $fields['author'] = '<p class="comment-form-author">' . ( $req ? '<span class="required">*</span>' : '' ) . 
  '<input id="author" name="author" type="text" placeholder="Your Name*" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>';
  
  // removes label & adds placeholder to email field.        
  $fields['email'] = '<p class="comment-form-email">' . ( $req ? '<span class="required">*</span>' : '' ) . 
  '<input id="email" name="email" type="text" placeholder="Your Email*" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>';
  
  $fields['url'] = ''; //removes website field

  return $fields;
}
add_filter('comment_form_default_fields','wpsites_modify_comment_form_fields');
/* 
** Code from:
** http://wpsites.net/web-design/customize-comment-form-place-holder-input-text-fields-labels/ 
*/

/* **************************************************** */
/* Customize the text before and after comment form     */
/* **************************************************** */
function wpsites_change_note_after_comment_form($arg) {
    // $arg['comment_notes_after'] = '<p class="comment-notes">' . __( 'Thanks for leaving an awesome comment!' ) . '</p>';
    $arg['comment_notes_after'] = '';
    return $arg;
}
add_filter('comment_form_defaults', 'wpsites_change_note_after_comment_form');

function wpsites_modify_text_before_comment_form($arg) {
    // $arg['comment_notes_before'] = '<p class="comment-notes">' . __( 'We respect your privacy and will not publish your personal details.' ) . '</p>';
    $arg['comment_notes_before'] = '';
    return $arg;
}
add_filter('comment_form_defaults', 'wpsites_modify_text_before_comment_form');
/* 
** Code from:
** http://wpsites.net/web-design/modify-text-before-after-comment-form/
*/

// function alter_comment_form_fields($fields){
//     //$fields['author'] = ''; //removes name field
//     //$fields['email'] = '';  //removes email field
//     //$fields['url'] = '';  //removes website field
//     print_r($fields);
//     return $fields;
// }
// add_filter('comment_form_default_fields','alter_comment_form_fields');
/*
** Code from:
** http://chipcullen.com/altering-the-comment-form-in-wordpress/
*/

以上是关于php Wordpress自定义注释循环和注释表单的主要内容,如果未能解决你的问题,请参考以下文章

自定义表单验证注释不起作用

如何自定义Wordpress comment_form();

PHP Wordpress - 自定义循环SQL查询(和热门帖子示例)

php 在WordPress中自定义登录表单

PHP 使用循环外的自定义字段自定义Wordpress查询

php WordPress - 自定义帖子类型循环