function.php調査vol.4|WordPress
- 2010.10.06
| TonTonだよ。 |
| 昨日に引き続き、function.phpの調査を進めていきます。 |
| 「ウィジェット」を利用してみようかな。 |
| 現在「ウィジェット」をクリックすると |
![]() |
| 「ウィジェットは使用できません」と警告が出ています。 |
| そりゃ~ function.php に記述がないもんね。 |
| ということで function.phpに |
| /************/ //ウィジェット register_sidebar(); |
| を記述してアップ。 |
![]() |
| 使えるようになりました。 右側に「サイドバー1」が表示された! |
| 「アーカイブ」「最新の投稿」「カテゴリー」をドラッグしてサイドバー1へ持っていく |
![]() |
| ホームページを確認します。 |
![]() |
| エラーが出てるね~ |
| Fatal error: Call to undefined function twentyten_posted_on() in /home2/whitepla/public_html/02/wp-content/themes/twentyten/loop.php on line 129 |
| loop.php on line 129 を見てみます。 |
![]() |
| 129行目に書かれている <?php twentyten_posted_on(); ?> |
| そしてエラーの |
| Fatal error: Call to undefined function twentyten_posted_on() in /home2/whitepla/public_html/02/wp-content/themes/twentyten/loop.php on line 129 |
| この調査をする前にオリジナルのfunction.phpをコピーしておいたのでそのfunction.phpを調査します。 |
| 464行目に function twentyten_posted_on の記述がありました。 |
![]() |
| functionにはこの記述がないからエラーが出てるんだね。 |
twentyten_posted_on() |
| TwentyTen独自関数でtwentyten_posted_on()はその記事の投稿日と投稿者を表示する |
| なるほど |
| <?php function twentyten_posted_on() { printf( __( ‘<span class=”%1$s”>Posted on ‘meta-prep meta-prep-author’, sprintf( ‘<a href=”%1$s” title=”%2$s” rel=”bookmark”><span class=”entry-date”>%3$s</span></a>’, get_permalink(), esc_attr( get_the_time() ), get_the_date() ), sprintf( ‘<span class=”author vcard”><a class=”url fn n” href=”%1$s” title=”%2$s”>%3$s</a></span>’, get_author_posts_url( get_the_author_meta( ‘ID’ ) ), sprintf( esc_attr__( ‘View all posts by %s’, ‘twentyten’ ), get_the_author() ), get_the_author() ) );}?> |
| ということで上記の記述をfunction.phpの中に書きます。 |
![]() |
| エラーが消えました。 |
| 右側のサイドバーにも「アーカイブ」「最近の投稿」「カテゴリー」が表示されています。 |
| ※このウィジェットは表示させたいところに<?php dynamic_sidebar(); ?> ウィジェットで指定したメニューを出力するためのタグです。 |
| ちなみに |
| /************/ //ウィジェット register_sidebar(); |
| ↓↓↓ |
| /************/ //ウィジェット register_sidebar(); register_sidebar(); |
| ふたつ記述してアップすると |
| サイドバー2が出てきました! |
![]() |
| 出力させたいところに |
| <?php dynamic_sidebar(1); ?> <?php dynamic_sidebar(2); ?> |
| サイドバー1は<?php dynamic_sidebar(1); ?>で、 サイドバー2は<?php dynamic_sidebar(2); ?>で出力されます。 |
















