TopMovable Typeカスタマイズコメント > コメント投稿者の表示を valid にする
News
各種ブログテンプレート
2008年11月12日

エントリー本文

コメント投稿者の表示を valid にする

Posted at November 12,2008 1:55 AM
Category:[コメント, テンプレートタグ]
Tag:[, , , ]

コメント投稿者の表示には MTCommentAuthorLink タグを使用していますが、コメント投稿者名に「&」などの実体参照が必要な文字が含まれている場合、そのページが valid でなくなります。

グローバルモディファイアとして、escape モディファイアや encode_html モディファイアが用意されていますが、MTCommentAuthorLink タグにこのモディファイアを適用すると、タグで出力されるリンク(のアングルブラケット)まで実体参照されてしまいます。

1.通常のコメント投稿者表示で MTCommentAuthorLink タグを使用

下は通常のコメント投稿者表示で MTCommentAuthorLink タグを使用した場合の、サブテンプレートとその出力(ソースコード)です。

Posted by <mt:commentAuthorLink default_name="Anonymous" show_email="0" />

出力

Posted by <a title="http://www.koikikukan.com/" href="http://www.koikikukan.com/" rel="nofollow">yujiro</a>

2.MTCommentAuthorLink タグに escape モディファイアを適用した失敗例

下は、MTCommentAuthorLink タグに escape モディファイアを適用したときの、サブテンプレートとその出力(ソースコード)です。出力で、本来アングルブラケットになるべき (X)HTML 要素のタグが実体参照されてしまっています。

Posted by <mt:commentAuthorLink default_name="Anonymous" show_email="0" escape="html" />

出力

Posted by &lt;a title=&quot;http://www.koikikukan.com/&quot; href=&quot;http://www.koikikukan.com/&quot;&gt;yujiro&lt;/a&gt;

ここでは、他のテンプレートタグを組み合わせて、コメント投稿者を実体参照するカスタマイズを紹介します。

3.配布テンプレートの修正例

ブログ管理画面より「デザイン」→「テンプレート」で「コメント詳細」テンプレートモジュール編集画面を開き、赤色の MTCommentAuthorLink タグの部分を、青色の内容に変更してください。

変更前

<div class="comment"<mt:ifArchiveTypeEnabled archive_type="Individual"> id="c<mt:commentID />"</mt:ifArchiveTypeEnabled>>
 
   <div class="comment-content">
   <mt:ifCommentParent>
   <p><a href="<mt:commentParent>#comment-<mt:commentID /></mt:commentParent>"><mt:commentParent>No.<mt:commentID />の<mt:commentAuthor /></mt:commentParent></a>さんのコメントへの返信</p>
   </mt:ifCommentParent>
   <mt:commentBody /></div>
 
   <p class="comment-footer">
      Posted by <mt:commentAuthorLink default_name="Anonymous" show_email="0" /> <mt:if tag="CommentAuthorIdentity"><mt:commentAuthorIdentity /></mt:if> at <mt:commentDate /><mt:ifCommentsAccepted> | <mt:commentReplyToLink /></mt:ifCommentsAccepted>
   </p>
</div>

変更後

<div class="comment"<mt:ifArchiveTypeEnabled archive_type="Individual"> id="c<mt:commentID />"</mt:ifArchiveTypeEnabled>>
 
   <div class="comment-content">
   <mt:ifCommentParent>
   <p><a href="<mt:commentParent>#comment-<mt:commentID /></mt:commentParent>"><mt:commentParent>No.<mt:commentID />の<mt:commentAuthor escape="html" /></mt:commentParent></a>さんのコメントへの返信</p>
   </mt:ifCommentParent>
   <mt:commentBody /></div>
 
   <p class="comment-footer">
      Posted by <mt:if tag="commentURL"><a href="<mt:commentURL />"></mt:if><mt:commentAuthor default="Anonymous" escape="html" /><mt:if tag="commentURL"></a></mt:if> <mt:if tag="CommentAuthorIdentity"><mt:commentAuthorIdentity /></mt:if> at <mt:commentDate /><mt:ifCommentsAccepted> | <mt:commentReplyToLink /></mt:ifCommentsAccepted>
   </p>
</div>

4.デフォルトテンプレート(抜粋)の修正例

ブログ管理画面より「デザイン」→「テンプレート」で「コメント」テンプレートモジュール編集画面を開き、赤色の MTCommentAuthorLink タグの部分を、青色の内容に変更してください。

変更前

...前略...
<div class="asset-meta">
  <span class="byline">
<$mt:CommentAuthorIdentity$>
<mt:IfCommentParent>
    <span class="vcard author"><$mt:CommentAuthorLink$></span>から<a href="<mt:CommentParent><$mt:CommentLink$></mt:CommentParent>"><mt:CommentParent><$mt:CommentAuthor$></mt:CommentParent></a>への返信
<mt:Else>
    <span class="vcard author"><$mt:CommentAuthorLink$></span>
</mt:IfCommentParent>
    | <a href="<$mt:CommentLink$>"><abbr class="published" title="<$mt:CommentDate format_name="iso8601"$>"><$mt:CommentDate$></abbr></a>
<mt:IfCommentsAccepted>
    | <$mt:CommentReplyToLink$>
</mt:IfCommentsAccepted>
  </span>
</div>
...後略...

変更後

...前略...
<div class="asset-meta">
  <span class="byline">
<$mt:CommentAuthorIdentity$>
<mt:IfCommentParent>
    <span class="vcard author"><mt:if tag="commentURL"><a href="<mt:commentURL />"></mt:if><mt:commentAuthor default="Anonymous" escape="html" /><mt:if tag="commentURL"></a></mt:if></span>から<a href="<mt:CommentParent><$mt:CommentLink$></mt:CommentParent>"><mt:CommentParent><$mt:CommentAuthor$></mt:CommentParent></a>への返信
<mt:Else>
    <span class="vcard author"><mt:if tag="commentURL"><a href="<mt:commentURL />"></mt:if><mt:commentAuthor default="Anonymous" escape="html" /><mt:if tag="commentURL"></a></mt:if></span>
</mt:IfCommentParent>
    | <a href="<$mt:CommentLink$>"><abbr class="published" title="<$mt:CommentDate format_name="iso8601"$>"><$mt:CommentDate$></abbr></a>
<mt:IfCommentsAccepted>
    | <$mt:CommentReplyToLink$>
</mt:IfCommentsAccepted>
  </span>
</div>
...後略...
Posted by yujiro
この記事を読んだ人はこんな記事も読んでいます
関連記事
人気エントリー
Hatena Hot Entries
Hatena Entries
トラックバックURL


コメント

コメントについて考え中です。
色々と参考にさせていただいています。

[1] Posted by https://me.yahoo.co.jp/a/CUllvXodTLJ2I7ZLyEiQ19mBOrWGTnILew--#26d8a Author Profile Page : March 27, 2009 10:01 PM
コメントする
greeting

*必須



ご質問のコメントの回答については、内容あるいは多忙の場合、1週間以上かかる場合があります。また、すべてのご質問にはお答えできない可能性があります。予めご了承ください。

太字 イタリック アンダーライン ハイパーリンク 引用
[サインインしない場合はここにCAPTCHAを表示します]

コメント投稿後にScript Errorや500エラーが表示された場合は、すぐに再送信せず、ブラウザの「戻る」ボタンで一旦エントリーのページに戻り(プレビュー画面で投稿した場合は、投稿内容をマウスコピーしてからエントリーのページに戻り)、ブラウザをリロードして投稿コメントが反映されていることを確認してください。

コメント欄に(X)HTMLタグやMTタグを記述される場合、「<」は「&lt;」、「>」は「&gt;」と入力してください。例えば「<$MTBlogURL$>」は「&lt;$MTBlogURL$&gt;」となります(全て半角文字)

Now loading...
Introduction
Entries of this Category
Recent Entries
Recent Comments
Recent Trackbacks
QRcode

現在停止中です
携帯電話からこのQRcodeを撮影することで携帯用URLを取得することができます

URI for cellular phones
ギターに入った猫
Styles
Font Size
Default
For defective color vision
Gray Scale
RGB Color
Search this site

このブログをメールで購読する by:FeedBurner

loading ...
Categories
Monthly Archives
BlogPeople
Now loading...
Syndicate this site
FeedBurner(RSS1.0/RSS2.0/Atom)
Counter
これまでのアクセス
クリエイティブ・コモンズ・ライセンス
Powered by
Movable Type 4.261
 
List Me!