查询在 localhost 中工作,但在 live 中不工作

Query work in localhost, but not in live

我需要制作iframe url,例如:

https://url.com/category/{category_name)/t=desktop || /t=mobile.

我在 运行 我的本地开发环境中使用 MAMP,我让它正常工作,当查询字符串等于桌面时,它显示 3 posts,然后当移动时只有一个 post。现在问题来了,当系统管理员更新 pre-live env 时,他可以从日志中看到这个错误:

[Wed Nov 15 20:09:42.122140 2017] [:error] [pid 7776] [client 10.1.2.66:41696] PHP Parse error: syntax error, unexpected end of file, expecting elseif (T_ELSEIF) or else (T_ELSE) or endif (T_ENDIF) in /var/lib/wordpress/wp-content/themes/wpTheme2/single_iframe.php on line 234

single-iframe.php 完整代码:https://pastebin.com/MBC6thDW

当我尝试去测试时 url 我得到错误 500 或 header 刚刚打印出查询功能。

我正在使用 PhpStorm IDE,它没有显示我的代码中的任何错误,我在这里遗漏了什么?

试试这个代码

https://pastebin.com/7ubTY2A4

<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="description" content="<?php bloginfo('description'); ?>">
    <?php
    if(get_field('fav_icon', 'option') != ''){
        $favId = get_field('fav_icon', 'option');
        $favDetails = wp_get_attachment_image_src($favId, 'full');
    }
    ?>
    <?php if(!empty($favDetails)): ?>
      <link rel="shortcut icon" href="<?php echo $favDetails[0]; ?>">
    <?php endif;?>




    <title><?php wp_title();?></title>


    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">


    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <?php wp_head(); ?>
    <!--[if (lt IE 9)&(!IEMobile)]>
    <link rel="stylesheet" type="text/css" href="enhanced.css" />
    <link rel="stylesheet" type="text/css" href="iframe.css" />
    <![endif]-->
    <?php
    if(is_front_page()){
        $info = get_bloginfo('description');

        echo '<meta name="og:description" content="'.$info.'">';
        echo '<meta name="og:title" content="Website">';
    }
    ?>
    <style>
        .main-header--frame {
            background-color: #a40057;
            margin-bottom: -40px;
        }
        .main-header--frame .categoryTitle {
            display: inline-block;
            padding-top: 19px;
            padding-left: 10px;
            color: #ffffff;
        }

        .main-header.main-header--frame .container {
            max-width: 1200px;
            background-color: transparent;
        }

    </style>

</head>
<body>
<header class="main-header main-header--frame">
    <nav>
        <div class="container">
            <div class="navbar-header">
                <a href="https://stiil.ee" class="navbar-brand">
                    <img src="logo" alt="logo"
                         class="img-responsive">
                </a>
                <h1 class="categoryTitle">Description</h1>
            </div>
        </div>
    </nav>
</header>
<main class="main-content main-content-inner valitud-content-inner">
    <div class="container">
            <?php
            $queried_object = get_queried_object();
            $taxChilds = get_terms( array(
                    'taxonomy' => 'category',
                    'hide_empty' => true,
                    'child_of' => $queried_object->term_id
            ) ); ?>

            <?php if(isset($_GET) && $_GET['t'] == 'desktop'): ?>
              <div class="category-wrap">
                            <?php
                            $queried_object = get_queried_object();
                            $count =0; 
                            foreach($taxChilds as $taxChild): ?>
                                <?php
                                $args = array(
                                        'post_type'=> 'post',
                                        'cat' => $taxChild->slug,
                                        'posts_per_page' => '1',
                                        'orderby' => 'rand',

                                        'tax_query' => array(
                                                array(
                                                        'taxonomy' => 'category',
                                                        'field'    => 'term_id',
                                                        'hide_empty' => false,
                                                        'terms'    =>  $taxChild->term_id,
                                                ),
                                        )
                                );
                                query_posts($args); if(have_posts()):
                                    while(have_posts()): the_post(); ?>
                                        <div class="col-md-4 all itemz <?php echo $taxChild->slug; ?>" data-cat="<?php echo $taxChild->slug; ?>">
                                            <div class="item-wrap">
                                                <a href="<?php the_permalink();?>"><?php the_post_thumbnail('size-370x416');
                                                                                $sponsored = get_field('is_sponsored_content');
                                                                                if($sponsored){
                                                                                    echo '<div class="sponsored-text">Ad</div>';
                                                                                };
                                                                                ?></a>
                                                <div class="overlay">
                                                    <div class="notify">
                                                        <a href="<?php the_permalink(); ?>"><img src="<?php echo get_post_cat_img_src();?>" alt=""></a>
                                                    </div>
                                                    <h2  class="categoryTitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                                </div>
                                            </div>
                                        </div>
                                    <?php endwhile; 

                                endif; wp_reset_query();?>
                                <?php
                                if ($count == 2) {
                                    break;
                                }
                                ?>
                                <?php $count++; endforeach;?>
              </div>
            <?php endif; ?>

            <?php if(isset($_GET) && $_GET['t'] == 'mobile'): ?>
              <div class="category-wrap">
                            <?php
                            $queried_object = get_queried_object();
                            $count =0;  foreach($taxChilds as $taxChild): ?>
                                <?php
                                $args = array(
                                        'post_type'=> 'post',
                                        'cat' => $taxChild->slug,
                                        'posts_per_page' => '1',
                                        'orderby' => 'rand',

                                        'tax_query' => array(
                                                array(
                                                        'taxonomy' => 'category',
                                                        'field'    => 'term_id',
                                                        'hide_empty' => false,
                                                        'terms'    =>  $taxChild->term_id,
                                                ),
                                        )
                                );
                                query_posts($args); 
                                if(have_posts()): 
                                    while(have_posts()): the_post(); ?>
                                <div class="col-md-4 all itemz <?php echo $taxChild->slug; ?>" data-cat="<?php echo $taxChild->slug; ?>">
                                    <div class="item-wrap">
                                        <a href="<?php the_permalink();?>"><?php the_post_thumbnail('size-370x416');
                                                                        $sponsored = get_field('is_sponsored_content');
                                                                        if($sponsored){
                                                                            echo '<div class="sponsored-text">SISUTURUNDUS</div>';
                                                                        };
                                                                        ?></a>
                                        <div class="overlay">
                                            <div class="notify">
                                                <a href="<?php the_permalink(); ?>"><img src="<?php echo get_post_cat_img_src();?>" alt=""></a>
                                            </div>
                                            <h2  class="categoryTitle"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                        </div>
                                    </div>
                                </div>
                                <?php endwhile; 
                                endif; wp_reset_query();?>
                                <?php
                                if ($count == 0) {
                                    break;
                                }
                                ?>
                                <?php $count++; endforeach;?>
              </div>
            <?php endif; ?>

    </div>
</main>
</body>

<!--main-content ends-->
<?php wp_footer(); ?>

这是因为短标签。 在您的本地主机环境中使用“<?”已启用,在您的开发服务器中未启用。这是唯一的原因。

http://php.net/manual/en/language.basic-syntax.phptags.php

那么,只需替换“< ?”使用“< ?php”,它将正常工作。