普通网友 2014-08-22 17:51
浏览 183
已采纳

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

I have used google custom search engine and used their code provided in my website.

I have this issue in the (search.php) that I cant place the < ?php endif; ?> and I get an error ( Parse error: syntax error, unexpected 'endif' (T_ENDIF) )

How can I add that endif on the search.php file ?


this is part where I use the google code:
<?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条回答 默认 最新

  • dshgnt2008 2014-10-10 11:25
    关注

    I managed to change where to add the code and here is the full code of 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(); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog