こんにちは
WordPress3.51
VERSION: 1.0.3.2で試してみましたが、
<?php
hoge();
function hoge(){echo 'hoge';}
?>ddddddd
として、数種類のテンプレートで試してみましたが、動作するみたいです。
どんな、エラーが出るのですか?
トピック投稿者
Kite
(@ixkaito)
nobitaさん、こちらの質問にもご回答いただきましてありがとうございます。
再度色々試してみましたところ、どうやら
<?php
while ( have_posts() ) : the_post();
endwhile;
?>
のループ内で下記のエラーが出ます。
Fatal error: Call to undefined function hoge() in /〜〜.php on line ◯◯
single.phpのwhile loopの中で、関数を使ってみましたが、私の環境では、hogeがechoされて、エラーは、発生していないようです。
テストしたコード
<div id="container">
<?php
// action hook for placing content above #content
thematic_abovecontent();
// filter for manipulating the element that wraps the content
echo apply_filters( 'thematic_open_id_content', '<div id="content">' . "\n\n" );
// start the loop
while ( have_posts() ) : the_post();
hoge();
// create the navigation above the content
thematic_navigation_above();
// calling the widget area 'single-top'
get_sidebar('single-top');
// action hook creating the single post
thematic_singlepost();
// calling the widget area 'single-insert'
get_sidebar('single-insert');
// create the navigation below the content
thematic_navigation_below();
// action hook for calling the comments_template
thematic_comments_template();
// end the loop
endwhile;
function hoge(){echo 'hoge';}
// calling the widget area 'single-bottom'
get_sidebar('single-bottom');
?>
</div><!-- #content -->
<?php
// action hook for placing content below #content
thematic_belowcontent();
?>
</div><!-- #container -->
想像ですが、while loopの中で、関数を定義していませんか?
fatal errorは、ループの中で関数が定義されて、二回目のループで、同じ関数が定義されているために出ているのではないかと思います。
トピック投稿者
Kite
(@ixkaito)
想像ですが、while loopの中で、関数を定義していませんか?
してました!
fatal errorは、ループの中で関数が定義されて、二回目のループで、同じ関数が定義されているために出ているのではないかと思います。
同じループ内でも、先に関数を定義した場合は問題ないでしょうか?