Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP multiline string with PHP

I need to echo a lot of PHP and HTML.

I already tried the obvious, but it's not working:

<?php echo ' <?php if ( has_post_thumbnail() ) {   ?>       <div class="gridly-image"><a href="<?php the_permalink() ?>"><?php the_post_thumbnail('summary-image', array('class' => 'overlay', 'title'=> the_title('Read Article ',' now',false) ));?></a>       </div>       <?php }  ?>        <div class="date">       <span class="day">         <?php the_time('d') ?></span>       <div class="holder">         <span class="month">           <?php the_time('M') ?></span>         <span class="year">           <?php the_time('Y') ?></span>       </div>     </div>     <?php }  ?>'; ?> 

How can I do it?

like image 738
Matt Avatar asked Sep 21 '12 16:09

Matt


People also ask

What is PHP heredoc used for?

Heredoc is one of the ways to store or print a block of text in PHP. The data stored in the heredoc variable is more readable and error-free than other variables for using indentation and newline. How the heredoc content can be stored in a variable or printed has shown in this tutorial.

How do you concatenate in PHP?

The first is the concatenation operator ('. '), which returns the concatenation of its right and left arguments. The second is the concatenating assignment operator (' . = '), which appends the argument on the right side to the argument on the left side.


1 Answers

You don't need to output php tags:

<?php      if ( has_post_thumbnail() )      {         echo '<div class="gridly-image"><a href="'. the_permalink() .'">'. the_post_thumbnail('summary-image', array('class' => 'overlay', 'title'=> the_title('Read Article ',' now',false) )) .'</a></div>';     }      echo '<div class="date">               <span class="day">'. the_time('d') .'</span>               <div class="holder">                 <span class="month">'. the_time('M') .'</span>                 <span class="year">'. the_time('Y') .'</span>               </div>           </div>'; ?> 
like image 120
Josh Avatar answered Sep 24 '22 11:09

Josh