וורדפרס ואתרי אינטרנט

owl-158414_960_720
דורג 5 מתוך 5

באתר תמצאו מדריכים ומאמרים ייחודים בעברית, המדריכים לרוב מנסיון מעשי ומיוחסים לפרוייקטים שאני עובד עליהם באותו הזמן. האתר הוא יותר לשימוש פרטי ולתיעוד דברים, בכדי להשתמש מאוחר יותר, אבל החלטתי לפרסם ניתן לשאול כל שאלה וגם לתרום מדריכים באתר דרך תגובה או דרך צור קשר

בקובץ  comments.php, האחראי על תצוגת התגובות, יכולות להימצא מספר פונקציות, כגון wp_list_comments או comment_author_link, או get_comment_author_link. כל אחת מהפונקציות האלה בסופו של דבר עוברת דרך הפילטר ששמו get_comment_author_link.

add_filter('get_comment_author_link', func);

נסביר קצת על הפונקציה wp_list_comments ,

תפקידה להציג את כל התגובות שנשלחו לפוסט הספציפי.

<?php wp_list_comments( $args, $comments ); ?>

הארגומנטים שהיא יכולה לקבל :

<?php $args = array(
  'walker'            => null,
  'max_depth'         => '',
  'style'             => 'ul',
  'callback'          => null,
  'end-callback'      => null,
  'type'              => 'all',
  'reply_text'        => 'Reply',
  'page'              => '',
  'per_page'          => '',
  'avatar_size'       => 32,
  'reverse_top_level' => null,
  'reverse_children'  => '',
  'format'            => 'html5', // or 'xhtml' if no 'HTML5' theme support
  'short_ping'        => false,   // @since 3.6
        'echo'              => true     // boolean, default is true
); ?>

 

אפשר לראות פה  מה התפקיד של כל ארגומנט במערך.

דוגמא להצגת תגובות בלי שום ארגומנט

<ol class="commentlist">
<?php wp_list_comments(); ?>
</ol>

 

במידה והגדרנו פונקציית callback אזי יש לכתוב את הפונקציה בקובץ functions.php

<ol class="comment-list">
  <?php
    wp_list_comments( array(
      'style'      => 'ol',
      'short_ping' => true,
      'callback' => 'mytheme_comment',
    ) );
  ?>
</ol><!-- .comment-list -->

הפונקציה mytheme_comment

function mytheme_comment($comment, $args, $depth) {
  $GLOBALS['comment'] = $comment;
  extract($args, EXTR_SKIP);

  if ( 'div' == $args['style'] ) {
    $tag = 'div';
    $add_below = 'comment';
  } else {
    $tag = 'li';
    $add_below = 'div-comment';
  }
?>
  <<?php echo $tag ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID() ?>">
  <?php if ( 'div' != $args['style'] ) : ?>
  <div id="div-comment-<?php comment_ID() ?>" class="comment-body">
  <?php endif; ?>
  <div class="comment-author vcard">
  <?php if ( $args['avatar_size'] != 0 ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
  <?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?>
  </div>
  <?php if ( $comment->comment_approved == '0' ) : ?>
    <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></em>
    <br />
  <?php endif; ?>

  <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>">
    <?php
      /* translators: 1: date, 2: time */
      printf( __('%1$s at %2$s'), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), '  ', '' );
    ?>
  </div>

  <?php comment_text(); ?>

  <div class="reply">
  <?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  </div>
  <?php if ( 'div' != $args['style'] ) : ?>
  </div>
  <?php endif; ?>
<?php
}

 

ניתן גם להגדיר תגובות לעמוד או פוסט ספיציפי

<ol class="commentlist">
  <?php
    //Gather comments for a specific page/post 
    $comments = get_comments(array(
      'post_id' => XXX,
      'status' => 'approve' //Change this to the type of comments to be displayed
    ));

    //Display the list of comments
    wp_list_comments(array(
      'per_page' => 10, //Allow comment pagination
      'reverse_top_level' => false //Show the latest comments at the top of the list
    ), $comments);
  ?>
</ol>

 

תפריט נגישות