语法错误,Single.php文件上的意外文件结束

时间:2014-05-25 07:55:15

标签: php wordpress parsing syntax

在添加此代码之前,我的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/

当我添加它时,我收到此错误:&#34;语法错误,意外的文件结束&#34;

我多次检查了我的代码语法,没有什么遗漏!!

1 个答案:

答案 0 :(得分:2)

您的代码遗失了2 }

代码的最后几行应该是:

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

?>

而不是:

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