的末尾刪除;
這裏有一對夫婦的事情,你應該注意的。
1)你在你的代碼中分號:
echo '<li><a href="#section_' . get_post_meta($post->ID, 'sub_nav_name', true); . '">' . the_title(); . '</a></li>';
// Should be:
echo '<li><a href="#section_' . get_post_meta($post->ID, 'sub_nav_name', true) . '">' . the_title() . '</a></li>';
2)endforeach
使用 「備用」 語法:
備用PHP語法應該儘可能避免,爲了標準,可讀性和防止下一個必須閱讀你的代碼的人狩獵你並用一把生鏽的刀刺你。
由於這些語法是「備用」,因此可以安全地假定這些不是推薦的執行操作的方法。雖然他們確實有用,並且目前還沒有任何計劃會反對這種功能,但我不會長期指望他們,因爲PHP開始捲入失控的方法論。
foreach($how_posts as $post) :
// Should be:
foreach($how_posts as $post) {
and
endforeach;
// Should be:
}
例子:
<?php
foreach($how_posts as $post) {
setup_postdata($post);
echo '<li><a href="#section_' . get_post_meta($post->ID, 'sub_nav_name', true) . '">' . the_title() . '</a></li>';
$nav_items[] = html_entity_decode(get_the_title(), ENT_QUOTES, 'UTF-8');
}
我不知道......問題是什麼?如果你告訴我們你遇到了什麼錯誤,這可能會有所幫助。 – 2013-03-20 20:54:46
什麼是foreach(...):? – sircapsalot 2013-03-20 20:54:47
@sircapsalot速記語法 – AlienWebguy 2013-03-20 20:55:12