谷歌自定义搜索错误(解析错误:语法错误,意外'endif'(T_ENDIF))

时间:2014-08-22 17:51:57

标签: php google-search parse-error

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

我在(search.php)中遇到了这个问题,我无法将其放在< ?php endif; ?>我收到一个错误(解析错误:语法错误,意外' endif'(T_ENDIF))

如何在search.php文件中添加该endif?

<小时/> 这是我使用谷歌代码的一部分:

<?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>     

1 个答案:

答案 0 :(得分:0)

我设法更改了添加代码的位置,这里是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(); ?>