douchengfei3985 2018-08-25 13:51
浏览 72

PHP语法错误,意外'回声'[重复]

This question already has an answer here:

This my function, I do not know why there is a problem.

Parse error: syntax error, unexpected 'echo' (T_ECHO) in D:\OSPanel...

<?php function set_gallery($type_filter) { ?>
  <?php $gallery_postes = array();

  $args = set_arges($type_filter); //Create $ARGS and RETURN $set_args

  $gallerys_posts = new WP_Query($args);



  if( $gallerys_posts->have_posts() ) :
    while ( $gallerys_posts->have_posts() ) :
      $gallerys_posts->the_post();

      $retgel = '
      <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12 shuffle-item filtered">
        <div class="portfolio-item">
          <a href="' .echo get_permalink(get_the_id());.'">'.

^--[there is a problem here]

            if ( get_the_post_thumbnail(get_the_id()) )  {
              echo get_the_post_thumbnail( get_the_id(), array(620, 423 ));
            }
            .'<div class="portfolio-overlay">
              <div class="caption">'.
                the_title();
                .'<span>'.
                  echo get_the_content();
                .'</span>
              </div>
            </div>
          </a>
        </div>
      </div>';

      array_push($gallery_postes, $retgel);
  endwhile; endif; // new WP_Query ?>

  <?php return $gallery_postes; ?>

<?php } ?>
</div>
  • 写回答

1条回答 默认 最新

  • douju1968 2018-08-25 14:17
    关注

    Welcome to StackOverflow Viktor Vasilick,

    To "answer" your question, I would simply say you need to remove the word "echo" and the closing ";". However, I don't feel that will do you justice in an answer, the fact you have written it like this shows you may need some better understanding of PHP, so I'll try and give you some pointers.

    You've created a variable with a bunch of string data, and in the middle, you've added the dynamic data get_permalink(). When you're assigning a variable with dynamic data inside, PHP will interpret dynamic data like that into the variable for you. However, as you tried to echo in the middle of creating a load of string data in a weird way, it's thrown you that error.

    In future always try and establish and create your block of text first, and then echo it out afterwards (or array_push as you were trying to do in your example.

    Here's how your code should look:

    <?php
    function set_gallery($type_filter) {
      $gallery_postes = array();
      $args = set_arges($type_filter); //Create $ARGS and RETURN $set_args
      $gallerys_posts = new WP_Query($args);
    
    
    
      if( $gallerys_posts->have_posts() ) :
        while ( $gallerys_posts->have_posts() ) :
          $gallerys_posts->the_post();
          $retgel = '<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12 shuffle-item filtered">
            <div class="portfolio-item">
              <a href="'.get_permalink(get_the_id()).'">
                '.
                if ( get_the_post_thumbnail( get_the_id() ) ) {
                  echo get_the_post_thumbnail( get_the_id(), array(620, 423 ));
                }
                .'
                <div class="portfolio-overlay">
                  <div class="caption">
                    '.the_title().'
                    <span>'.get_the_content().'</span>
                  </div>
                </div>
              </a>
            </div>
          </div>';
    
          array_push($gallery_postes, $retgel);
        endwhile;
      endif; // new WP_Query
      ?>
      <?php return $gallery_postes; ?>
    <?php
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?