0

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

1 Answers1

1

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
}
?>
Alexander Wigmore
  • 3,157
  • 4
  • 38
  • 60