我正在寫php代碼。我一直在解析錯誤,例如 意外'?>'期待功能()。我似乎做的都是正確的。這個問題是一個非常基本的性質,可能是關於匹配標籤。我經歷了許多次的代碼,但無法找到問題出在哪裏。請爲這個微不足道的問題。任何幫助將讚賞。 謝謝。PHP代碼解析錯誤
<?php
class My_Widget extends WP_Widget {
function widget($args, $instance) {
// output the content of widget
extract($args);
echo $before_width;
echo $before_title. 'In this section'. $after_title;
//run query if on the page
if ((is_page)) {
$ancestor = check_page_tree();
// arguments for the children of ancestors.
$args = array('child_of' => $ancestor,
'depth' => $instance['depth'],
'title_li' => '');
// set value for get_pages to check if it's empty
$list_pages = get_pages($args);
//check if $list_pages has value.
if($list_pages) {
// open a list with the ancestor page at the top
?>
<ul class="page_tree">
//list ancestor page
<li class="ancestor">
<a href="<?php echo get_permalink($ancestor); ?>">
<?php echo get_the_title($ancestor);?></a>
</li>
<?php
//use wp_list_pages to list subpages of ancestor or page
wp_list_pages($args);
?>
</ul>
<?php
}
}
}
?> <---------- here is the error unexpected ?> ------|
<?php
function form($instance) {
$defaults = array(
'depth' => '-1'
);
$depth = $instance[ 'depth' ];
// markup for form ?>
<p>
<label for="<?php echo $this->get_field_id('depth'); ?>">
Depth of list: </label>
<input class = "widefat" type = "text"
id="<?php echo $this->get_field_id('depth'); ?>"
name="<?php echo $this->get_field_name('depth'); ?>" value="
<?php echo esc_attr($depth) ; ?>" />
</p>
<?php
}
// end of class
}
?>
什麼是is_page過嗎?功能?變量?不變? –
爲什麼要關閉標籤?你只是有一個新的行,然後再次打開PHP?嘗試正確和一致地縮進您的代碼,並且更容易看到這些錯誤。 –
@Barmar - 是的,我意識到這一點,這就是爲什麼我改變了我的評論。 :) –