Another HTML-lintで100点を目指せ

現状

dw2009071701 550x364 Another HTML lintで100点を目指せ

すでに、「よくできました。」である。
もうゴールしても良さそうな点数だけど、気になるので修正。


・<div>と</div>の間が空です。
ヘッダ部にある広告*1とか、ページ送り(前ページ、次ページ)が問題の部分。

前ページ次ページがなければ、何も出力されないのでdiv間が空になってしまうってわけだ。

[html]
<div class=”navigation”>
<div class=”left”><?php next_posts_link(‘&laquo; 前ページ’, 0) ?></div>
<div class=”right”><?php previous_posts_link(‘次ページ &raquo;’, 0) ?></div>
</div>
[/html]

divで括らなければいいんだろうけど、スタイルに必要なので消すわけにも行かない。

頑張ってWordPressタグの中にdiv突っ込めば良いじゃないかと思うかもしれないけど、それだとaタグの中にdivが来てしまう。これはよろしくない。*2

ならば、divタグから表示しないようにすればいいじゃない。

前ページ次ページの有無を調べて、無かったらdivタグごと出力しないようにする。

編集するのはindex.phpとsingle.phpかな。

index.php

[php]
<?php $next_posts_link = get_next_posts_link(‘&laquo; 前ページ’, 0); ?>
<?php $previous_posts_link = get_previous_posts_link(‘次ページ &raquo;’, 0); ?>
<?php if((isset($next_posts_link)) || (isset($previous_posts_link))): ?>
<div class=”navigation”>
<?php if(isset($next_posts_link)): ?>
<div class=”left”><?php echo $next_posts_link; ?></div>
<?php endif; ?>
<?php if(isset($previous_posts_link)): ?>
<div class=”right”><?php echo $previous_posts_link; ?></div>
<?php endif; ?>
</div>
<?php endif; ?>
[/php]

single.php

[php]
<?php $next_post = get_next_post(); ?>
<?php $previous_post = get_previous_post(); ?>
<?php if(!(empty($next_post) && empty($previous_post))): ?>
<div class=”navigation”>
<?php if(!empty($previous_post)): ?>
<div class=”left”><?php previous_post_link(‘&laquo; %link’, ‘前の記事’); ?></div>
<?php endif; ?>
<?php if(!empty($next_post)): ?>
<div class=”right”><?php next_post_link(‘%link &raquo;’, ‘次の記事’); ?></div>
<?php endif; ?>
</div>
<?php endif; ?>
[/php]

next_posts_linkはhtmlを”echo”で出力してるだけなので、next_posts_linkの中で呼んでる関数get_next_posts_linkを使用。
こっちはhtmlをreturnしてくれるので、変数に入れる事が出来る。ページが無かったら変数の中身は空、あったらhtmlが入ってる。

・<a>にはname属性とid属性の両方を指定するようにしましょう。
これはWP-Footnotesっていうプラグインが出力した部分が問題。nameがないようですね。
footnotes.phpのそれっぽいところにname=”‘.$id_id.’”を追加。属性値はidと一緒でいいや。

footnotes.php 216行目のaタグ

[php num=208]
foreach ($identifiers as $key => $value) {
$id_id = “identifier_”.$key.”_”.$post->ID;
$id_num = ($style == ‘decimal’) ? $value['use_footnote']+$start_number : $this->convert_num($value['use_footnote']+$start_number, $style, count($footnotes));
$id_href = get_permalink($post->ID).”#footnote_”.$value['use_footnote'].”_”.$post->ID;
$id_title = str_replace(‘”‘, “&quot;”, strip_tags($value['text']));
if (is_feed()){
$id_replace = $this->current_options['pre_identifier'].$id_num.$this->current_options['post_identifier'];
}else{
$id_replace = $this->current_options['pre_identifier'].’<a href=”‘.$id_href.’” id=”‘.$id_id.’” name=”‘.$id_id.’” class=”footnote-link footnote-identifier-link” title=”‘.$id_title.’”>’.$id_num.’</a>’.$this->current_options['post_identifier'];
}
if ($this->current_options['superscript']) $id_replace = ‘<sup>’.$id_replace.’</sup>’;
if ($display) $data = substr_replace($data, $id_replace, strpos($data,$value[0]),strlen($value[0]));
else $data = substr_replace($data, ”, strpos($data,$value[0]),strlen($value[0]));
}

[/php]

・<a>のアンカーXXXXはXXX行目で異なるリンク先を刺しています。
最新のコメントの部分ですね。
これWordPressのウィジェットなんだが…

アンカーの範囲をコメント書いた人の名前まで広げれば問題ないんだろうけど、スペースが入ってるから不格好になりそう。
title属性を付ければ良いみたいなので、title属性を付けることにする。
属性値は適当に投稿者で。

default-widgets.php 645行目

[php num=641]
<?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=”‘.get_comment_author().’ より”>’ . get_the_title($comment->comment_post_ID) . ‘</a>’) . ‘</li>’;
endforeach; endif;?></ul>
<?php echo $after_widget; ?>
[/php]

・<li>のclass属性の前には空白が必要です。
これはプラグインCategory Orderがやったこと。
インデントしてる部分のようですな。

スペース追加で終了。

category-order.php

[php num=531]
// $html .= ‘”‘ . $id_to_item[$category_order[$i][0]] . “\n”;
$html .= ‘” ‘ . $id_to_item[$category_order[$i][0]] . “\n”;
[/php]

これで100点かな。

dw2009071702 550x282 Another HTML lintで100点を目指せ

脚注

  1. 今はないけど [戻る]
  2. インライン要素の中にブロック要素入れたらダメ。 [戻る]

コメント/トラックバック (1件)

  1. [...] よね。 そんなときに、どうしたらよいのか調べましたら、だずりんぐわーるどつぅさんの「Another HTML-lintで100点を目指せ」のページで紹介されていましたので、使わせていただきました。 [...]

コメントする

(管理人にのみ公開されます)

上へ参ります。