I’m not entirely sure why this isn’t working. But this piece of code does not work.
<?php
foreach ( $gallery_ids as $gallery ) {
echo '<div class="tgallery" rel="'.$gallery['gid'].'"><?php echo do_shortcode("[nggallery id='.$gallery['gid'].']"); ?></div>';
}
?>
I was guessing that maybe I’m putting the wrong quotes in the wrong place.
All the parts seperately work, as in :
- I can display the
'gid'
value withecho $gallery['gid']
- I can make the div tags appear with the appropriate
rel
- I can, by itself, make
<?php echo do_shortcode("[nggallery id=3]"); ?>
work.
I just can’t make the entire thing appear together.
You’re mixing interpolated php and html, placing
"<?php echo"
inside what’s already php.Why you put
<?php ?>
inside your echo ?The issue
Pick either string concatenation or opening/closing PHP for HTML. You cannot combine both as you have done above.
The second line of code above does not belong inside a string as code in between the
<?php ... ?>
will not be parsed by PHP when it is contained in a string.Solutions
Concatenation
I have fixed your code to use concatenation below:
Opening and closing PHP
This is how you would do it using PHP “templating”:
You are already “in” php, so your opening tag is causing the problem:
It should be something like:
try this….
you have inside a php statment
Try Notepad then it will colour code your php code, so you can clearly see what quotes etc you have wrong