此代码导致
解析错误:语法错误,第18行的C:\ wamp64 \ www \ pss \ wp-content \ themes \ pss-theme \ index.php中的意外文件结尾
<?php
get_header();
if (have_posts()) :
$count = 1;
while (have_posts()) : the_post();
get_template_part ('content');
get_sidebar();
get_footer();
?>
但是如果我从index.php移动if,count和while,
<?php
get_header();
get_template_part ('content');
get_sidebar();
get_footer();
?>
到内容模板部分的顶部,如下所示:
<?php if (have_posts()) :
$count = 1;
while (have_posts()) : the_post(); ?>
<div class="post-content u-cf">
<?php if (has_post_thumbnail()) { ?>
<div class="post-thumbnail u-cf">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('small-thumbnail') ?>
</a>
</div>
<?php } ?>
<h2 class="post">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="post-info">
<i class="fa fa-folder-open" aria-hidden="true"></i>
<?php
$categories = get_the_category();
$separator = ", ";
$output = '';
if ($categories) {
foreach ($categories as $category) {
$output .= '<a href="' . get_category_link($category->term_id) . '">' . $category->cat_name . '</a>' . $separator;
}
echo trim ($output, $separator);
}
?>
|
<i class="fa fa-clock-o" aria-hidden="true"></i> <?php the_time('j/m/Y'); ?>
</p>
<?php the_content(); ?>
<hr>
<?php if ( 2 === $count ) { ?>
<div class="main-content-advert">
<p>Lorem ipsum</p><p>Lorem impsum</p>
</div>
<hr>
<?php }
$count++; ?>
</div>
<?php endwhile; ?>
<?php
else :
echo '<p> No Content found</p>';
endif;
?>
</article>
</div>
错误不存在。
现在,我知道它与循环或计数有关?
答案 0 :(得分:0)
这是完全正常的,因为您错过了import mechanize
br = mechanize.Browser() # now you are at first login page
br.open('someurl.com')
br.select_form(nr=0) # select the form from the first login page
br.form['user'] = 'myname'
br.form['pw'] ='pw'
req=br.submit() # now you are at second login page
br.select_form(nr=0) # select the form from the second login page
br.form['user'] = 'myname'
br.form['pw'] ='pw'
req=br.submit()
和if
的结束标记,所以会出现错误。
您 cant 将这些文件放在不同的文件中,while
期望开头和结尾位于同一个文件中。
它不像它会执行PHP
函数并创建一个包含所有这些部分的大文件,然后从它们的内容开始。
如果您希望变量get_XXXX
位于模板部分中,请将结束标记移动到索引中,并且只包含内容模板中的内容,这是他的目的;)
$count
然后在<?php
get_header();
if (have_posts()) :
$count = 1234;
while (have_posts()) : the_post();
get_template_part('template-parts/post/content');
endwhile;
else :
echo '<p> No Content found</p>';
endif;
?>
</article>
</div>
<?php
get_sidebar();
get_footer();
?>
中使用content.php
来获取不在范围内的变量:
global
您可以在variable scope
找到更多信息