我在WordPress单页php编码中遇到错误

时间:2020-05-24 作者:Ansarul Haque

我在WordPress single page中遇到错误当移动网站时,此页面在另一台服务器中正确加载其他服务器出现错误

致命错误:未捕获错误:语法错误,意外的“endwhile”(T\\u endwhile)

在/单个产品中。php第149行下面的php代码,如果有人能帮我解决,我会非常感谢,提前谢谢,我已经尝试解决了无法解决的问题,下面是我的代码

<?php
/**
 * The template for displaying all single product
 *
 * @package WordPress
 * @subpackage Duralift
 * @since Duralift 1.0
 */

get_header(); ?>

  <div id="primary" class="content-area">!!
    <div id="content" class="site-content" role="main">

      <section id="product-list" class="section">
      <div class="bandInner">
          <p><?php single_term_title( \'Currently browsing \' ); ?>.</p>

      <?php /* The loop */ 
      ?>
<?php 
$terms = get_the_terms( $post->ID, \'product_category\');
foreach ( $terms as $term ) {
    $termname = $term->name;
}
echo "<h2 class=\'pageTitle\'> $termname </h2>";
?>
<? 
wp_nav_menu( array( 
    \'theme_location\' => \'product-category\',
    \'container\'      => \'ul\',
    \'menu_class\'     => \'prodCats\',
) );

?>
<style>
ul.prodCats li{
    display:initial!important;
}
ul.prodCats li.current-product-parent a {
    color: #8b2131!important;
}
</style>
      <?php
          $cats = get_the_terms($post->ID, \'product_category\');
          $current_cat = "";
          $current_cat_slug= "";

          foreach($cats as $cat) {
            $current_cat = $cat->name;
            $current_cat_slug = $cat->slug;
            //echo "<h2 class=\'pageTitle\'>" . $cat->name . "</h2>";
          }

          $terms = get_terms( \'product_category\' );
    $args = array(
                \'post_type\'     => \'product\',
                \'product_category\'  => $current_cat_slug,
              );
          $query = new WP_Query($args); ?>
<?php while ( have_posts() ) : the_post(); ?>

        <?php //get_template_part( \'content\', get_post_format() ); ?>
        <?php //duralift_post_nav(); ?>
        <?php //comments_template(); ?>
<div class="product-cntnt">
        <div class="prodCtn">
          <div class="prodImgCtn">
            <?php
            $img = wp_get_attachment_image_src( get_field(\'product_image\'), "thumb_product" );
            ?>
            <?php $image_alt = get_post_meta( $attributes[\'uni_card_image\'][\'id\'], \'_wp_attachment_image_alt\', true); ?>
            <img class="prodImg" src="<?php echo $img[0]; ?>" alt="<?php echo esc_attr( $img[\'title\'] ); ?>"/>
          </div>
          <div class="prodCont product-half product-mid">
            <h1 class="prodHd"><?php the_title(); ?></h1>
            <div class="prodPara">
              <a href="<?php the_field(\'product_specs\'); ?>" class="popupTrigger downloadLink">
                <img src="<?php echo get_template_directory_uri() . "/images/icons/pdf.gif"; ?>" />
                View product specs
              </a>
            </div>
            <?php if ( get_field( \'product_description\' ) ) { ?>
            <div class="prodPara">

              <p><?php the_field(\'product_description\'); ?></p>
            </div>
            <?php } ?>
            <?php if ( get_field( \'suitable_for\' ) ) { ?>
            <div class="prodPara">
              <span class="themeColor1">Suitable for:</span>
              <p><?php the_field(\'suitable_for\'); ?></p>
            </div>
            <?php } ?>
            <a class="callto" href="tel:1300 580 580"><span class="icon fa fa-phone"></span> 1300 580 580</a>
            <!--<a href="<?php echo get_bloginfo(\'url\') . \'?productID=\' . get_the_ID() . \'#quickquote\' ?>" class="btn">-->
            <!--  <span class="btnTxt">Quick Quote</span>-->
            <!--</a>-->
          </div>
          <div class="product-half hidden-xs product-form">
              <h5>QUICK QUOTE</h5>
    <?php echo do_shortcode(\'[contact-form-7 id="3009" title="QUICK QUOTE NEW"]\');?>
          </div></div>
<div class="pro-des">
  <div class="tabs">
<?php if(get_field(\'product_information\')): $i = 0; ?>
 <?php while(has_sub_field(\'product_information\')): $i++; ?>
  <input type="radio" name="tabs" id="section-<?php echo $i; ?>" checked="checked">
  <label for="section-<?php echo $i; ?>"><?php the_sub_field(\'title\'); ?></label>
  <div class="tab <?php the_sub_field(\'title\'); ?>" id="">
     <?php the_sub_field(\'content\'); ?>
     </div>
      <?php endwhile; ?>
<?php endif; ?>
      <input type="radio" name="tabs" id="section-vid" checked="checked">
      <?php if(get_field(\'video-instructions\')): 
      while(has_sub_field(\'video-instructions\')):?>
  <label for="section-vid">Video & Instructions</label>
  <div class="tab">
       <div class="inner-tab">
           <?php if(get_sub_field(\'pdf_file\')): ?>
<div class="pro-pdf-section">
    <div class="icon-pdf"><img src="https://wmiserver.com/dura/wp-content/uploads/2020/02/pdf-icon.png"/></div>
    <div class="file-pdf">
        <?php the_sub_field(\'pdf_title\'); ?>
        <br>
<a href="<?php the_sub_field(\'pdf_file\'); ?>" target="_blank">DOWNLOAD</a></div></div>
    <?endif?>
  <?php $Vidlink = get_sub_field(\'video\'); ?>
  <?php if( $Vidlink ){ ?>
      <div class="pro-vid-section">

    <?
$link_url = $Vidlink;
$urlArr = explode("/", $Vidlink );
$urlArrNum = count($urlArr);

// Youtube video ID
$youtubeVideoId = $urlArr[$urlArrNum - 1];
// Generate youtube thumbnail url
$thumbURL = \'https://i.ytimg.com/vi/\'.$youtubeVideoId.\'/0.jpg\';
 echo do_shortcode (\'[wp-video-popup video="\'.$Vidlink.\'"]\');
echo \'  <a href="#" class="wp-video-popup img-respomsive"><img src="\'.$thumbURL.\'"/></a>\';  
the_sub_field(\'video_title\');         
?>
          </div>
      <?php}?>
     </div></div>
<?php endwhile; ?><?php endif; ?>
</div>
  </div>
  <div class="product-half visible-xs mobile-only product-form">
             <h5>QUICK QUOTE</h5>
    <?php echo do_shortcode(\'[contact-form-7 id="3009" title="QUICK QUOTE NEW"]\');?>
          </div>

  </div>
<div class="single_related">
<div class="r-heading">
    <h4>DO YOU ALSO NEED</h4>
</div>
  <?  //Get array of terms
$terms = get_the_terms( $post->ID , \'product_tags\', \'string\');
//Pluck out the IDs to get an array of IDS
$term_ids = wp_list_pluck($terms,\'term_id\');

//Query posts with tax_query. Choose in \'IN\' if want to query posts with any of the terms
//Chose \'AND\' if you want to query for posts with all terms
  $second_query = new WP_Query( array(
      \'post_type\' => \'product\',
      \'posts_per_page\' => 4,
      \'ignore_sticky_posts\' => 1,
      \'orderby\' => \'rand\',
      \'post__not_in\'=>array($post->ID)
   ) );

//Loop through posts and display...
    if($second_query->have_posts()) {

     while ($second_query->have_posts() ) : $second_query->the_post(); ?>

          <div class="related-items">
           <div class="related-item-inner">
           <?php if (has_post_thumbnail()) { ?>
            <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"> <?php the_post_thumbnail( \'related_sm\', array(\'alt\' => get_the_title()) ); ?> </a>
            <?php } else { ?>
            <?php } ?><div class="r-img"><a class="prodImgCtn prodLink" href="<?php echo get_permalink(); ?>">
                    <?php 
                    $img = wp_get_attachment_image_src( get_field(\'product_image\'), "thumb_product" ); 
                    ?>
                    <img class="prodImg" src="<?php echo $img[0]; ?>"/>
                  </a></div>
                  <div class="r-info">
                  <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
                  </div>
 </div></div>
   <?php endwhile; wp_reset_query();
   }  ?></div>
 <?php endwhile; ?></div>
        </section>
    </div><!-- #content -->

  </div><!-- #primary -->
  <style>
@media (max-width:768px){
   .product-half.hidden-xs {
    display: none;
} 
.mobile-only{
    margin-top:30px;
}
}
@media (min-width:768px){
   .product-half.visible-xs {
    display: none;
} 
}
.pro-vid-section img {
    width: 100%;
}
.Features ul {
    list-style: inherit;
    column-gap: 20px;
    width: 50%;
    float: left;
    padding: 0px 25px;
}
.pro-vid-section {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    grid-gap: 20px;
}
.icon-pdf {
    width: 20%;
    height: auto;
}
.icon-pdf img {
    width: 100%;
}
.pro-pdf-section {
    display: flex;
}
.inner-tab {
    display: grid;
    grid-template-columns: 30% 65%;
    grid-gap: 30px;
}
.inner-tab, .tabs label{
    text-transform: uppercase;
}
.inner-tab a{
    font-size:14px;
}
@media(max-width:768px){
    .inner-tab {
    grid-template-columns: 100%;
}
.pro-vid-section {
    grid-template-columns: 100%;
}
#Features ul{
    width:100%;
}
}

.pro-vid-section iframe {
    width: 100%;
    height: 186px;
}
.tabs {
  display: -webkit-box;
  display: flex;
  flex-wrap: wrap;
  width:100%;

}

.tabs label {
    -webkit-box-ordinal-group: 2;
    order: 1;
    display: block;
    padding: 1rem 16px;
    cursor: pointer;
    background: transparent;
    -webkit-transition: background ease 0.2s;
    transition: all ease 0.2s;
    font-size: 15px;
    font-weight: 600;
    top: 1px;
    position: relative;
}

.tabs .tab {
  -webkit-box-ordinal-group: 100;
          order: 99;
  -webkit-box-flex: 1;
          flex-grow: 1;
  width: 100%;
  display: none;
  padding: 1rem;
  background: #fff;
  border-top: 1px solid #cccccc;

}

.tabs input[type="radio"] {
  display: none;
}
.tabs input[type="radio"]:checked{
    transition: all ease 0.2s;
}
.tabs input[type="radio"]:checked + label {
    background: #fff;
    border-left: 1px solid #cccccc;
    border-top: 1px solid #cccccc;
    border-right: 1px solid #cccccc;
    top: 1px;
    position: relative;
    color: #8b2131;
     transition: all ease 0.2s;
}

.tabs input[type="radio"]:checked + label + .tab {
  display: block;
}

@media (max-width: 45em) {
  .tabs .tab,
  .tabs label {
    -webkit-box-ordinal-group: initial;
            order: initial;
  }

  .tabs label {
    width: 100%;
    margin-right: 0;
    margin-top: 0.2rem;
  }
.tabs input[type="radio"]:checked + label {
    background:#8b2131;
    color: #fff!important;
}
.tabs label {
    background:black ;
    color: #fff!important;
}
}
</style>
  <script>
    var elements = document.querySelectorAll(\'[name=tabs]:first-child\');
Array.prototype.forEach.call(elements, function(el) { el.checked = true; });
</script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script>
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
(function($) {
  $.fn.uncheckableRadio = function() {
    var $root = this;
    $root.each(function() {
      var $radio = $(this);
      if ($radio.prop(\'checked\')) {
        $radio.data(\'checked\', true);
      } else {
        $radio.data(\'checked\', false);
      }

      $radio.click(function() {
        var $this = $(this);
        if ($this.data(\'checked\')) {
          $this.prop(\'checked\', false);
          $this.data(\'checked\', false);
          $this.trigger(\'change\');
        } else {
          $this.data(\'checked\', true);
          $this.closest(\'form\').find(\'[name="\' + $this.prop(\'name\') + \'"]\').not($this).data(\'checked\', false);
        }
      });
    });
    return $root;
  };
}(jQuery));

$(\'[type=radio]\').uncheckableRadio();
}
        </script>
<style>
@media(max-width:560px){
.tabs input[type="radio"]:checked + label:after {
    content: "\\f106";
    position: absolute;
    right: 10px;
    font-family: fontAwesome;
    font-size: 25px;
}
.tabs label:after {
    content: "\\f107";
    position: absolute;
    right: 10px;
    font-family: fontAwesome;
    font-size: 25px;
}
.tabs input[type="radio"]:checked + label + .tab {
    overflow-x: scroll;
}    

}
.tabs input[type="radio"]:checked + label:after, .tabs label:after{
    transition: all 0.5s;
}
   .tabset > input[type="radio"] {
  position: absolute;
  left: -200vw;
}

.tabset .tab-panel {
  display: none;
}

.tabset > input:first-child:checked ~ .tab-panels > .tab-panel:first-child,
.tabset > input:nth-child(3):checked ~ .tab-panels > .tab-panel:nth-child(2),
.tabset > input:nth-child(5):checked ~ .tab-panels > .tab-panel:nth-child(3),
.tabset > input:nth-child(7):checked ~ .tab-panels > .tab-panel:nth-child(4),
.tabset > input:nth-child(9):checked ~ .tab-panels > .tab-panel:nth-child(5),
.tabset > input:nth-child(11):checked ~ .tab-panels > .tab-panel:nth-child(6) {
  display: block;
}
/*
 Styling
*/

.tabset > label {
  position: relative;
  display: inline-block;
  padding: 15px 15px 25px;
  border: 1px solid transparent;
  border-bottom: 0;
  cursor: pointer;
  font-weight: 600;
}

.tabset > label::after {
  content: "";
  position: absolute;
  left: 15px;
  bottom: 10px;
  width: 22px;
  height: 4px;
  background: #8d8d8d;
}

.tabset > label:hover,
.tabset > input:focus + label {
  color: #8b2131;
}

.tabset > label:hover::after,
.tabset > input:focus + label::after,
.tabset > input:checked + label::after {
  background: #8b2131;
}

.tabset > input:checked + label {
  border-color: #ccc;
  border-bottom: 1px solid #fff;
  margin-bottom: -1px;
}

.tab-panel {
  padding: 30px 0;
  border-top: 1px solid #ccc;
  font-size: 14px;
}

/*
 Demo purposes only
*/
*,
*:before,
*:after {
  box-sizing: border-box;
}


.tabset {
    max-width: 100%;
    margin: 10px;
}
.prodCtn{border:none;}
.product-cntnt {
    border: 1px solid #cccccc;
}
.product-mid{margin-bottom: 40px;}
.product-half {
    width: 50%;
    float: left;

}
a.callto {
    background: #99c66b;
    padding: 10px;
    text-align: center;
    margin: auto;
    display: table;
    margin-top: 30px;
    color: #fff;

}
a.callto span {
    color: #8b2131;
}
@media(max-width:1000px){
    .product-half {
    WIDTH: 100%;
}

}
@media(max-width:768px){
.tabset > input:checked + label {
    width: 100%;
}
.tabset > label {
    width: 100%;
}}
table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

td, th {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}

tr:nth-child(even) {
  background-color: #dddddd;
}
#infFormIframe_0 {
    height: 570px!important;
}
.wp-google-badge.wp-google-badge-fixed {
    display: none;
}
.related-item-inner {
    margin: 5px;
    border: 1px solid #dddddd;
    height: 250px;
    position: relative;
    overflow: hidden;
    border-bottom: 2px solid #8b2131;

}
.related-item-inner a {
    transition: all 0.5s;
    text-decoration: none;
}
.related-item-inner a:hover {
    color:black;
}
    .related-items {
    width: 25%;
    float: left;
}
.related-items img {
    width: 100%;
    height: 185px;
    object-fit: contain;
    margin:auto;
}
.related-items {
 text-align: center;
 transition: all 0.5s;
}
.r-info {
    background: #ffffff;
    margin: auto;
    align-items: center;
    position: absolute;
    bottom: 0;
    width: 100%;
    padding: 20px 4px;
    font-size: 15px;
    border-top: 1px solid #dddddd;
}
.related-items:hover .r-img {
    transform: scale(1.2);
}
.r-img {
    transition: all .5s;
}
.r-heading h4 {
    font-size: 20px;
    font-weight: 800!important;
}

.single_related{
margin-top: 40px;
display:inline-block;
}
@media(max-width:768px){
.related-items {
    width: 100%;
}}
</style>
<?php get_footer(); ?>
``````


1 个回复
SO网友:swtshweta

您的代码几乎没有问题:

您在少数地方没有正确添加php起始代码语法(即,您应该编写<?php 而不是<? ).

  • 您必须删除出现在代码末尾的```````````
  • 通过实施这些修复,您现有的错误有望得到修复。