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?
To do that, you must remove all
'
charachters in your string or use an escape character. Like:The internal set of single quotes in your code is killing the string. Whenever you hit a single quote it ends the string and continues processing. You'll want something like:
Use the
show_source();
function of PHP. Check for more details in show_source. This is a better method I guess.Use Heredocs to output muli-line strings containing variables. The syntax is...
The "HEREDOC" part is like the quotes, and can be anything you want. The end tag must be the only thing on it's line i.e. no whitespace before or after, and must end in a colon. For more info check out the manual.
You cannot run PHP code within a string like that. It just doesn't work. As well, when you're "out" of PHP code (
?>
), any text outside of the PHP blocks is considered output anyway, so there's no need for theecho
statement.If you do need to do multiline output from with a chunk of PHP code, consider using a HEREDOC:
Another option would be to use the
if
with a colon and anendif
instead of the brackets: