我已经成功创建了一个轮播 html 页面,其中对一些 php 函数的调用正在成功运行
<?php
function getPictureType($ext) {
if ( preg_match('/jpg|jpeg/i', $ext) ) {
return 'jpg';
} else if ( preg_match('/png/i', $ext) ) {
return 'png';
} else if ( preg_match('/gif/i', $ext) ) {
return 'gif';
} else {
return '';
}
}
function getPictures($id) {
global $max_width, $max_height;
$dir="../../images/albums/album".$id."/";
$i = 0;
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
echo '<ul >';
while (($file = readdir($dh)) !== false) {
if ( !is_dir($file) ) {
$absolute_path = $dir.'thumbs';
$split = explode('.', $file);
$ext = $split[count($split) - 1];
$textfile = $dir.$split[0].'.txt';
if (file_exists($textfile)) {
$description = file_get_contents($textfile);
}
if ( ($type = getPictureType($ext)) == '' ) {
continue;
}
if ($i == 0) {
echo $i;
echo '<a href="'.$dir.$file.'" rel="lightbox['.$id.']" title="'.$description.'"><div class="linkicon"><i class="icon-plus-circled"></i></div></a>';
}
else
{
echo $i;
echo '<a href="'.$dir.$file.'" rel="lightbox['.$id.']" title="'.$description.'"></a>';
}
$i=$i+1;
}
}
echo '</ul>';
closedir($dh);
}
}
}
?>
然后我在 html 中调用它们
<div class="hovercover" style="opacity: 0;">
<?php getPictures(1); ?>
</div>
这样就可以毫无问题地构建灯箱。
我现在尝试使用 default.php 文件中的相同代码创建一个模块,但<$php getPictures(1); ?>
没有调用该函数,也没有生成灯箱图像。default.php 看起来像这样
defined('_JEXEC') or die('Restricted access'); // no direct access
// get the document object
$doc =& JFactory::getDocument();
// add your stylesheet
$doc->addStyleSheet( 'modules/mod_hot_joomla_carousel/tmpl/style.css' );
// add lightbox stylesheet
$doc->addStyleSheet( 'modules/mod_hot_joomla_carousel/tmpl/lightbox.css' );
?>
<?php if ($enablejQuery!=0) { ?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8./jquery.min.js"></script>
<?php } ?>
<!-- Carousel plugin -->
<script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/modules/mod_hot_joomla_carousel/js/jquery.carouFredSel-6.2.1-packed.js"></script>
<!-- lightbox plugins -->
<script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/modules/mod_hot_joomla_carousel/js/lightbox.js"></script>
<!-- optionally include helper plugins -->
<script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/modules /mod_hot_joomla_carousel/js/helper-plugins/jquery.mousewheel.min.js"></script>
<script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/modules/mod_hot_joomla_carousel/js/helper-plugins/jquery.touchSwipe.min.js"></script>
<script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/modules/mod_hot_joomla_carousel/js/helper-plugins/jquery.transit.min.js"></script>
<script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/modules/mod_hot_joomla_carousel/js/helper-plugins/jquery.ba-throttle-debounce.min.js"></script>
<script type="text/javascript">
jQuery(function() {
// Scrolled by user interaction
jQuery('#foo2').carouFredSel({
auto: false,
prev: '#foo2_prev',
next: '#foo2_next',
mousewheel: true,
swipe: {
onMouse: true,
onTouch: true
}
});
});
</script>
<?php
function getPictureType($ext) {
if ( preg_match('/jpg|jpeg/i', $ext) ) {
return 'jpg';
} else if ( preg_match('/png/i', $ext) ) {
return 'png';
} else if ( preg_match('/gif/i', $ext) ) {
return 'gif';
} else {
return '';
}
}
function getPictures($id) {
global $max_width, $max_height;
$dir="../../images/albums/album".$id."/";
$i = 0;
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
echo '<ul >';
while (($file = readdir($dh)) !== false) {
if ( !is_dir($file) ) {
$absolute_path = $dir.'thumbs';
$split = explode('.', $file);
$ext = $split[count($split) - 1];
$textfile = $dir.$split[0].'.txt';
if (file_exists($textfile)) {
$description = file_get_contents($textfile);
}
if ( ($type = getPictureType($ext)) == '' ) {
continue;
}
if ($i == 0) {
echo $i;
echo '<a href="'.$dir.$file.'" rel="lightbox['.$id.']" title="'.$description.'"><div class="linkicon"><i class="icon-plus-circled"></i></div></a>';
}
else
{
echo $i;
echo '<a href="'.$dir.$file.'" rel="lightbox['.$id.']" title="'.$description.'"></a>';
}
$i=$i+1;
}
}
echo '</ul>';
closedir($dh);
}
}
}
?>
<div class="divide30"></div>
<div class="wrapper whitebg">
<div class="divide20"></div>
<div class="image_carousel">
<div class="overflowholder" style="height: 350px;">
<ul id="foo2" style="width: 1920px; left: 0px; height: 303px;">
<!-- Image One -->
<li style="width: 223px;">
<div class="mediaholder">
<div class="mediaholder_innerwrap">
<img src="/../images/albums/album1/thumbs/thumb1.jpg" title="Image 1"/>
<div class="hovercover" style="opacity: 0;">
<?php getPictures(1); ?>
</div>
</div>
</div>
<div class="detailholder">
<div class="divide20"></div>
<div class="projects-title">
<a href="#"><?php echo $name1; ?></a>
</div>
<div class="divide15"></div>
<div class="projects-desc">
<?php echo $description1; ?>
</div>
</div>
</li>
<!-- Image Two -->
<li style="width: 223px;">
<div class="mediaholder">
<div class="mediaholder_innerwrap">
<img src="/../images/albums/album2/thumbs/thumb2.jpg" title="Image 2"/>
<div class="hovercover" style="opacity: 0;">
</div>
</div>
</div>
<div class="detailholder">
<div class="divide20"></div>
<div class="projects-title">
<a href="#"><?php echo $name2; ?></a>
</div>
<div class="divide15"></div>
<div class="projects-desc">
<?php echo $description2; ?>
</div>
</div>
</li>
<!-- Image Three -->
<li style="width: 223px;">
<div class="mediaholder">
<div class="mediaholder_innerwrap">
<img src="/../images/albums/album3/thumbs/thumb3.jpg" title="Image 3"/>
<div class="hovercover" style="opacity: 0;">
</div>
</div>
</div>
<div class="detailholder">
<div class="divide20"></div>
<div class="projects-title">
<a href="#"><?php echo $name3; ?></a>
</div>
<div class="divide15"></div>
<div class="projects-desc">
<?php echo $description3; ?>
</div>
</div>
</li>
<!-- Image Four -->
<li style="width: 223px;">
<div class="mediaholder">
<div class="mediaholder_innerwrap">
<img src="/../images/albums/album4/thumbs/thumb4.jpg" title="Image 4"/>
<div class="hovercover" style="opacity: 0;">
</div>
</div>
</div>
<div class="detailholder">
<div class="divide20"></div>
<div class="projects-title">
<a href="#"><?php echo $name4; ?></a>
</div>
<div class="divide15"></div>
<div class="projects-desc">
<?php echo $description4; ?>
</div>
</div>
</li>
<!-- Image Five -->
<li style="width: 223px;">
<div class="mediaholder">
<div class="mediaholder_innerwrap">
<img src="/../images/albums/album5/thumbs/thumb5.jpg" title="Image 5"/>
<div class="hovercover" style="opacity: 0;">
</div>
</div>
</div>
<div class="detailholder">
<div class="divide20"></div>
<div class="projects-title">
<a href="#"><?php echo $name5; ?></a>
</div>
<div class="divide15"></div>
<div class="projects-desc">
<?php echo $description5; ?>
</div>
</div>
</li>
<!-- Image Six -->
<li style="width: 223px;">
<div class="mediaholder">
<div class="mediaholder_innerwrap">
<img src="/../images/albums/album6/thumbs/thumb6.jpg" title="Image 6"/>
<div class="hovercover" style="opacity: 0;">
</div>
</div>
</div>
<div class="detailholder">
<div class="divide20"></div>
<div class="projects-title">
<a href="#"><?php echo $name6; ?></a>
</div>
<div class="divide15"></div>
<div class="projects-desc">
<?php echo $description6; ?>
</div>
</div>
</li>
</ul>
</div>
</div>
<div class="clearfix"></div>
<a class="prev" id="foo2_prev" href="#"><span>prev</span></a>
<a class="next" id="foo2_next" href="#"><span>next</span></a>
</div>
为什么getPictures函数没有被调用,是php函数的位置还是我在页面上调用它们的方式