您好我正在尝试创建一个模板,我可以动态地将模块放在模板的任何位置。
我的模板将具有以下位置:
的index.php
<html>
<head>
<title>Template with dynamic positions</title>
</head>
<body>
<?php include('header.php'); ?>
<div class="content">
<div class="content_top">All content top will go here</div>
<div class="column_left">All content left will go here</div>
<div class="column_right">All content right will go here</div>
<div class="content_bottom">All content bottom will go here</div>
</div>
<?php include('footer.php'); ?>
</body>
</html>
假设我创建了一个模块,我想将其添加到content_top,权重为0。
模块top.php
$weight = $_GET['weight'];
<div class="slideshow-<?php echo $weight ?>">
<img src="banner.jpg" alt="" />
</div>
如何将此插入到content_top位置?
答案 0 :(得分:1)
试试这个:
<div class="content_top"><?php include('module-top.php'); ?></div>
修改强>
你必须在javascript中对它进行排序。您可以使用冒泡排序
像这样:
var slideshows = $('.content_top div');
var len = slideshows.length;
for(var i = 0;i<len;i++)
for(var j = 0;j < len - 1; j++)
{
slideshows = $('.content_top div');
if(parseInt(slideshows[j].attr('class').replace('slideshow-', '')) > parseInt(slideshows[j + 1].attr('class').replace('slideshow-', '')))
{
slideshows[j].before(slideshows[j+1]);
slideshows[j+1].remove();
}
}
这是泡泡排序。这将对content_top
中的所有div进行排序。
答案 1 :(得分:0)
将php文件包含在content_top div
中 <div class="content_top">
<?php include('module-top.php'); ?>
</div>