我正在尝试编写index.php代码,但为了一些错误而运行一些代码。我试图从头开始列出博客并插入Wordpress编解码器的帖子链接。
这是索引文件的Wordpress代码。
<?php get_header(); ?>
<!-- BLOG AREA -->
<section>
<hr class="no-margin" />
<div class="blog-container section-content">
<div class="container">
<?php if (have_posts()) : ?>
<div class="row">
<?php while(have_posts()) : the_post(); ?>
<div class="col-md-8">
<ul class="negative-margin">
<li>
<h1><a href="<?php the_permalink(); ?>">" class="gray"><?php the_title(); ?></a></h1>
<p class="details">By <a href="#">Sam Norton</a> / On July 20, 2014 / <a href="#">Life Hacks</a></p>
<?php if (has_post_thumbnail()) : ?>
<figure>
<a href="<?php the_permalink(); ?>"><img class="opacity-hover box-layer img-responsive" src="<?php the_post_thumbnail(); ?>" alt="" /></a>
</figure>
<p class="excerpt">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
</p>
<div class="btn-margin">
<a href="<?php the_permalink(); ?>">" class="btn btn-primary">CONTINUE READING >>> </a>
</div>
<?php endif; ?>
</li>
<?php endwhile; ?>
</ul>
<div class="box-layer align-center page-nav">
<a href="#" class="btn">Next Page >>> </a>
</div>
</div>
<?php get_sidebar(); ?>
</div>
</div>
</section>
<?php get_footer(); ?>
然后我收到了以下错误:
Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\themewp\wp-content\themes\neoblog\index.php on line 51
知道导致此错误的原因是什么?我试图调整它,但没有找到运气。提前感谢您的帮助。
答案 0 :(得分:0)
我认为你没有关闭这个if
:
<?php if (have_posts()) : ?>
PHP并不期望该文件结束,因为它仍然期望相应的endif
答案 1 :(得分:0)
从所有锚中移除代码,额外>"
更改代码
<a href="<?php the_permalink(); ?>">" class="btn btn-primary">CONTINUE READING >>> </a>
到
<a href="<?php the_permalink(); ?>" class="btn btn-primary">CONTINUE READING >>> </a>
错过IF关闭也因此添加更多endif
<?php endif; ?>
所以完整的代码将是: -
<?php get_header(); ?>
<!-- BLOG AREA -->
<section>
<hr class="no-margin" />
<div class="blog-container section-content">
<div class="container">
<?php if (have_posts()) : ?>
<div class="row">
<?php while(have_posts()) : the_post(); ?>
<div class="col-md-8">
<ul class="negative-margin">
<li>
<h1><a href="<?php the_permalink(); ?>" class="gray">
<?php the_title(); ?>
</a></h1>
<p class="details">By <a href="#">Sam Norton</a> / On July 20, 2014 / <a href="#">Life Hacks</a></p>
<?php if (has_post_thumbnail()) : ?>
<figure> <a href="<?php the_permalink(); ?>"><img class="opacity-hover box-layer img-responsive" src="<?php the_post_thumbnail(); ?>" alt="" /></a> </figure>
<p class="excerpt">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum </p>
<div class="btn-margin"> <a href="<?php the_permalink(); ?>" class="btn btn-primary">CONTINUE READING >>> </a> </div>
</li>
<?php endif; ?>
<?php endwhile; ?>
</ul>
<div class="box-layer align-center page-nav"> <a href="#" class="btn">Next Page >>> </a> </div>
</div>
<?php endif; ?>
<?php get_sidebar(); ?>
</div>
</div>
</section>
<?php get_footer(); ?>
答案 2 :(得分:0)
** 1。你没有关闭
<?php if (have_posts()) : ?>
<?php endif(): ?>
in the end before <?php get_sidebar();?>**