1

Вывод аватара в блоке с комментариями Drupal

Is it that hard to include code for allowing user to select if they want to show user picture in the recent comment block?.
Well, Drupal 7 hasn't got that feature. So if you want to do it, as Drupal 6 you can either build custom block with views or theme the comment block to achieve it.

Here is the theme snippet for theming the recent comment block to show the user picture and comment body :



/**

 * Returns HTML for a list of recent comments to be displayed in the comment block.

 *

 * @ingroup themeable

 */

function yourthemename_comment_block() {

    global $theme_key;

    $output = '';

  $number = variable_get('comment_block_count', 10);

  foreach (comment_get_recent($number) as $comment) {

                // if core include it, it would be performance gain instead of calling comment_load again

        $comment_object = comment_load($comment->cid);

        !empty($comment_object->picture) && file_exists($comment_object->picture) ? $picture = $comment_object->picture : $picture = variable_get('user_picture_default', drupal_get_path('theme', $theme_key) . '/css/images/guest/anonymous50.png');

        $themed_picture = theme('image',    array('path' => $picture, 'alt' => $comment_object->name, 'title' => $comment_object->name , 'width' => '50px', 'height' => '50px'));

        $output .= '' . $comment_object->name .' ' . t('say') . ':' . t('@time ago', array('@time' => format_interval(time() - $comment_object->changed))) . '';

        $output .= '' .  l($themed_picture, 'user/' . $comment_object->u_uid, array('html' => TRUE)) . '';

        $output .= '' . l($comment->subject, 'node/'. $comment->nid) . '' . truncate_utf8($comment_object->comment_body[$comment_object->language][0]['value'], 50, $wordsafe = TRUE, $dots  = TRUE) . '';    

        if(!empty($output)) {

            return $output;

        }

        else {

            return t('No comments available.');

        }

    }

}

Enjoy the snippet and show that user picture in your comment block.
Got any improvement to the code or find some better way to do this? Post it in your comment.

Ограниченный HTML

  • Допустимые HTML-теги: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Строки и абзацы переносятся автоматически.
  • Адреса веб-страниц и email-адреса преобразовываются в ссылки автоматически.
CAPTCHA