たまにはチェック
たまにはAnother HTML-lint gatewayでチェックしてみる。
98点だった。
さて、修正するか。
■ <div> と </div> の間が空です。
記事を折りたたんだ時のセパレータとなる部分か…
元はspanなんだけど、続きがどこからか分かりやすくするために線を引きたかったからdivにしたのは良くなかったか…
てか、なんでdivにしたんだろ…hrでいいじゃん。
functions.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | /* 続きを読むの修正 *******************************************************************************/ add_action('the_content', moretag_custom, 100); function moretag_custom($content) { if (is_page() || is_single()) { $content = preg_replace( '/<span id="more-([0-9]+?)"><\/span>(.*?)/i', '</p><hr id="more-$1" class="entry" /><p>', $content ); } else { $content = preg_replace( '/\s*<a href="(.+?)#more-([0-9]+?)" class="more-link">(.+?)<\/a><\/p>/', '</p><p class="more-link"><a href="$1#more-$2" title="記事No.$2 の続きを読む">$3</a></p>', $content ); } $content = preg_replace( '/<p><\/p>/i', '', $content ); return $content; } |
■ <A> のアンカー `XXXX` は NN行目で異なるリンク先を指しています。
ユニークなtitle属性をつければいいんだけど、これって最近のコメントの部分でウィジェットなんだよね。ウィジェットのソース弄ったところで、WordPressのバージョンアップと共に元に戻るし…関数にフックもできないってか、echoだし…
もう、最近のコメントウィジェットのクラスWP_Widget_Recent_Commentsをコピーして自分用に変えるしかないか…
てことで、全部コピーするのは無駄が多いような気がしたので、WP_Widget_Recent_Commentsクラスのメソッドwidgetをオーバーライドしてみた。
functions.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | /* ウィジェット最近のコメントのクラスであるWP_Widget_Recent_Commentsの
** widgetをオーバーライド。
** リンクにtitle属性を追加。title="No.[コメントID]:[投稿日]@[投稿時間]"
*******************************************************************************/
class WP_Widget_Recent_Comments2 extends WP_Widget_Recent_Comments {
function WP_Widget_Recent_Comments2() {
parent::__construct();
}
function widget( $args, $instance ) {
global $wpdb, $comments, $comment;
extract($args, EXTR_SKIP);
$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title']);
if ( !$number = (int) $instance['number'] )
$number = 5;
else if ( $number < 1 )
$number = 1;
else if ( $number > 15 )
$number = 15;
if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) {
$comments = $wpdb->get_results("SELECT $wpdb->comments.* FROM $wpdb->comments JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID WHERE comment_approved = '1' AND post_status = 'publish' ORDER BY comment_date_gmt DESC LIMIT 15");
wp_cache_add( 'recent_comments', $comments, 'widget' );
}
$comments = array_slice( (array) $comments, 0, $number );
?>
<?php echo $before_widget; ?>
<?php if ( $title ) echo $before_title . $title . $after_title; ?>
<ul id="recentcomments"><?php
if ( $comments ) : foreach ( (array) $comments as $comment) :
echo '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '" title="No.' . get_comment_ID() . ':' . get_comment_date('Y.m.j') . '@' . get_comment_time('H:i:s') . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
endforeach; endif;?></ul>
<?php echo $after_widget; ?>
<?php
}
}
// ウィジェットを widgets_init フックで登録
add_action('widgets_init', create_function('', 'return register_widget("WP_Widget_Recent_Comments2");')); |
これをテーマのfunctions.phpに書いておけば、WordPressがバージョンアップしても大丈夫。
減点されていた個所は二つだけだったので、これで100点。

205StudioTR