Я пишу php-код. Я продолжаю получать ошибку синтаксического анализа. I 0e Неожиданный '?>' Ожидающая функция(). Кажется, я все делаю правильно. Проблема имеет очень простой характер, возможно, о совпадении тегов. Я много раз проделывал код, но не мог найти, где проблема. Выслушайте этот тривиальный вопрос. Любая помощь будет оценили. Спасибо.Ошибка анализа парсера 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? Функция? Переменная? Constant? –
Зачем вообще закрывать тег? У вас только есть новая строка, а затем снова открыть PHP? Попытайтесь правильно и последовательно отложить свой код, и вам будет легче увидеть эти ошибки. –
@ Бармар - Да, я понял это, поэтому я изменил свой комментарий. :) –