google自定义搜索错误(解析错误:语法错误,unexpected 'end '(T_ENDIF))


google custom search error (Parse error: syntax error, unexpected 'endif' (T_ENDIF) )

我使用了谷歌自定义搜索引擎,并在我的网站中使用了他们提供的代码。

我在(search.php)中有这个问题,我不能放置和我得到一个错误(解析错误:语法错误,意外的'endif' (T_ENDIF)))

我如何在search.php文件上添加结束符?


这是我使用google代码的部分:

<?php  $j=0; $i =0; if (have_posts()) : while (have_posts()) : the_post(); ?>
<script>
  (function() {
    var cx = '000306723311332550300:g5hpmnp8s68';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//www.google.com/cse/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<gcse:search></gcse:search>     

我设法改变添加代码的位置,这里是search.php的完整代码

<?php $mts_options = get_option('point'); ?>
<?php get_header(); ?>
<div id="page" class="home-page">
    <div class="content">
        <div class="article">
            <h1 class="postsby">
                <span><?php _e("Search Results for:", "mythemeshop"); ?></span> <?php the_search_query(); ?>
            </h1>   
            <?php  $j=0; $i =0; if (have_posts()) : while (have_posts()) : the_post(); ?>
<script>
  (function() {
    var cx = '000306723311332550300:tfoukb5efrq';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//www.google.com/cse/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<gcse:search></gcse:search>
</div>
                </article>
            <?php endwhile; else: ?>
                <div class="no-results">
                    <h5><?php _e('No Results found. We apologize for any inconvenience, please hit back on your browser or use the search form below.', 'mythemeshop'); ?></h5>
                    <?php get_search_form(); ?>
                </div><!--noResults-->
            <?php endif; ?> 
            <!--Start Pagination-->
            <?php if ( isset($mts_options['mts_pagenavigation']) && $mts_options['mts_pagenavigation'] == '1' ) { ?>
                <?php  $additional_loop = 0; global $additional_loop; mts_pagination($additional_loop['max_num_pages']); ?>           
            <?php } else { ?>
                <div class="pagination">
                    <ul>
                        <li class="nav-previous"><?php next_posts_link( __( '&larr; '.'Older posts', 'mythemeshop' ) ); ?></li>
                        <li class="nav-next"><?php previous_posts_link( __( 'Newer posts'.' &rarr;', 'mythemeshop' ) ); ?></li>
                    </ul>
                </div>
            <?php } wp_reset_query(); ?>
            <!--End Pagination-->           
        </div>
<?php get_footer(); ?>