【问题标题】:Wordpress index.php not workingWordpress index.php 不工作
【发布时间】:2014-07-10 04:30:07
【问题描述】:

我正在尝试编写 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

知道是什么导致了这个错误吗?我试图调整它,但没有运气。提前感谢您的帮助。

【问题讨论】:

  • 第 51 行是什么代码?

标签: php wordpress


【解决方案1】:

我认为你没有关闭这个if

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

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

【讨论】:

    【解决方案2】:

    从所有锚点中删除代码一个额外的&gt;"更改您的代码

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

    【讨论】:

    • 解析错误:语法错误,第 29 行 C:\xampp\htdocs\themewp\wp-content\themes\neoblog\index.php 中的意外 'endwhile' (T_ENDWHILE)
    【解决方案3】:

    **1。你没有关闭

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

    【讨论】:

      猜你喜欢
      • 2016-01-18
      • 2020-02-15
      • 1970-01-01
      • 1970-01-01
      • 2017-12-04
      • 1970-01-01
      • 2017-10-29
      • 1970-01-01
      • 2015-03-06
      相关资源
      最近更新 更多