简体   繁体   English

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

[英]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. 但我想在Joomla文章中实现自动化。 I installed Sourcer extension for inserting PHP code into Joomla articles. 我安装了Sourcer扩展,用于将PHP代码插入Joomla文章。 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. 这些行必须是常规HTML文章(没有PHP echo() ),但必须位于该PHP foreach()循环中。 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: 我不知道Sourcer,但是如果php echo是问题,请尝试内联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. 大概应该这样写整个页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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