Wordpress index.php not working


Wordpress index.php not working

我正试图编码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

你知道是什么导致这个错误吗?我试着调整一下,但运气不好。

我认为你没有关闭这个if:

<?php if (have_posts()) : ?>

PHP不期望文件结束,因为它仍然期望相应的endif

从所有锚中删除代码,额外的>"更改代码

<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(); ?>

**1。您没有关闭

 <?php if (have_posts()) : ?>
<?php endif(): ?>
 in the end before <?php get_sidebar();?>**