【问题标题】:syntax error, unexpected end of file on Single.php file语法错误,Single.php 文件上的文件意外结束
【发布时间】:2014-05-25 07:55:14
【问题描述】:

在我添加此代码之前,我的 single.php 文件没有错误:

<?php $orig_post = $post;
                global $post;
                $tags = wp_get_post_tags($post->ID);
                if ($tags) {
                $tag_ids = array();
                foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
                $args=array(
                'tag__in' => $tag_ids,
                'post__not_in' => array($post->ID),
                'posts_per_page'=>10, // Number of related posts that will be displayed.
                'caller_get_posts'=>1,
                'orderby'=>'rand' 
                );
                $my_query = new wp_query( $args );
                if( $my_query->have_posts() ) {
                echo '<div id="related_posts" class="clear"><h3>Related Posts</h3><ul>';
                while( $my_query->have_posts() ) {
                $my_query->the_post(); ?>
                <li>
                     <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
                     <?php the_post_thumbnail( 'related-posts' ); ?>
                     </a>
                     <div class="related_content">
                     <a href="<?php the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
                     </div>
                </li>
                <?php
                };
echo '</ul></div>'; ?>

,在我在这里找到的单个文件中获取基于类别的相关帖子的一段代码: http://www.webadvice.osvojito.com/wordpress-related-posts-without-plugin-with-thumbnails/

当我添加这个时,我得到这个错误:“语法错误,文件意外结束”

我检查了我的代码语法几次,没有任何遗漏!!

【问题讨论】:

    标签: php wordpress parsing syntax


    【解决方案1】:

    您的代码中缺少 2 }

    代码的最后几行应该是:

                    <?php
                    }
                    }
                    }
    echo '</ul></div>';
    
    ?>
    

    代替:

                    <?php
                    };
    echo '</ul></div>'; ?>
    

    【讨论】:

    • 天哪。我非常业余,我看不见他们:|非常感谢
    • 在 wordpres 模板中很容易错过。看看在 Sublime Text 中格式化的代码:pastebin.com/pAfMUmYp
    • 您缺少?&gt; 和代码结尾:D 顺便说一句,谢谢
    • 建议省略关闭标签:stackoverflow.com/questions/4410704/…
    • 但没有它我会出错。我正在使用 Zend Studio。它也给出了错误
    猜你喜欢
    • 1970-01-01
    • 2011-09-16
    • 2017-06-08
    • 2013-04-13
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    • 1970-01-01
    相关资源
    最近更新 更多