将PHP代码插入与HTML混合的Joomla文章中

暴力死亡

我有以下代码:

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

运行良好。但我想在Joomla文章中自动做到这一点。我安装了Sourcer扩展,用于将PHP代码插入Joomla文章。现在一切都很好,除了以下内容:

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

这些行必须是常规HTML文章(没有PHP echo()),但必须位于该PHPforeach()循环中。有人知道该怎么做吗?

boulder_02

我不知道Sourcer,但是如果php echo是问题,请尝试内联php:

...

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

...

那就是您上面提到的那行。大概应该这样写整个页面。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章