简体   繁体   中英

Inserting PHP code into Joomla article mixed with article HTML

I have this code:

<?php
$lastfile = null;
$files = glob('./images/fruits*.*');
foreach($files as $file) {
    $filename = pathinfo($file);
    $filepath1 = pathinfo($file, PATHINFO_BASENAME);
    $filepath2 = "images/fruits/".$filepath1;
    $base = basename($file, '.jpg');
    preg_match('#/([^/]+?)(?: \d+)?\.[^/]+$#', $file, $match);
    $filet = $match[1];
    if ($filet != $lastfile) {
       echo '{slider';
       echo '<strong>'.$filet.'</strong>|blue';
       echo '}';
       $lastfile = $filet;
       echo '<br>';
    }
    echo '{tip';
    echo "<img src=\"".$filepath2."\">";
    echo '}';
    echo "<img src=\"".$filepath2."\" "; 
    echo 'width="100" height="100" />{/tip}';
}
?>

It is running well. But I want to automatize that in Joomla article. I installed Sourcer extension for inserting PHP code into Joomla articles. Now everything is fine bexcept this:

echo '{slider';
echo '<strong>'.$filet.'</strong>|blue';
echo '}';

These lines must be a regular HTML article (no PHP echo() ) but in that PHP foreach() loop. Does anybody have idea how that can be done?

I don't know Sourcer, but if the php echo is the problem, try inline php:

...

if ($filet != $lastfile): ?>
   {slider<strong><?php echo $filet; ?></strong>|blue}
   <?php $lastfile = $filet; ?>
   <br>
<?php endif;

...

Thats just the lines you mentioned above. Probably you should write the whole page like that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM