- 2009-05-29 (金)
- カテゴリ:wordpress

wordpressでは記事エディタのmoreを押すと本文中に
<!–more–>
が挿入されます。
この状態で記事を投稿すると記事一覧ページには自動的に
「続きを読む」 (デフォルトでは (more…))
が挿入され,そこをクリックすることで記事ページの同じ位置にジャンプし続きから読めるようになっています。
記事の途中にジャンプすると一瞬どこに飛ばされたんだかよく分からないので余計なお世話な気がします。
以下の方法で,
「続きを読む」をクリックすると本文の先頭にジャンプするようにカスタマイズできます。
1.編集するファイルを開きます
バージョンによって対象ファイルが違います。
wordpressME2.0の場合
/wp-include/template-functions-post.php
wordpress2.5の場合
/wp-include/post-template.php
バージョンの近い方で探してみてください。
どちらのファイルも無い場合は
「the_content」という関数を探してください。
「function the_content」でgrep!
2.書き換える
template-functions-post.phpの場合
変更前
- if ( $more )
- $output .= '<a id="more-'.$id.'"></a>'.$content[1];
- else
- $output .= ' <a href="'. get_permalink() . "#more-$id\">$more_link_text</a>";
変更後
- if ( $more )
- // $output .= '<a id="more-'.$id.'"></a>'.$content[1];
- $output .= /*'<a id="more-'.$id.'"></a>'.*/$content[1];
- else
- // $output .= ' <a href="'. get_permalink() . "#more-$id\">$more_link_text</a>";
- $output .= ' <a href="'. get_permalink() . "\">$more_link_text</a>";
post-template.phpの場合
変更前
- if ( $more ) {
- $output .= '<span id="more-'.$id.'"></span>'.$content[1];
- } else {
- $output = balanceTags($output);
- if ( ! empty($more_link_text) )
- $output .= ' <a href="'. get_permalink() . "#more-$id\" class=\"more-link\">$more_link_text</a>";
- }
変更後
- if ( $more ) {
- // $output .= '<span id="more-'.$id.'"></span>'.$content[1];
- $output .= /*'<span id="more-'.$id.'"></span>'.*/$content[1];
- } else {
- $output = balanceTags($output);
- if ( ! empty($more_link_text) )
- // $output .= ' <a href="'. get_permalink() . "#more-$id\" class=\"more-link\">$more_link_text</a>";
- $output .= ' <a href="'. get_permalink() . "\" class=\"more-link\">$more_link_text</a>";
- }
- カテゴリ:wordpress

Comments:0
Trackback+Pingback:0
- TrackBack URL for this entry
- http://reoto.com/archives/242/trackback/
- Listed below are links to weblogs that reference
- wordpressの「続きを読む」を本文中の続きではなく本文の先頭にリンク from ぼんずーず