A-A+

ecshop新增单页面模板的方法

2015年07月06日 编程技术 暂无评论

单页面就是诸如站点的关于我们,联系我们之类的页面了,在ecshop中这样的单页面就很多了,比如售后服务,发货声明之类的都可以写成单页面来显示,在我们做商业模板的时候就可以添加这样的一个单页面来显示我们单页面的内容,下面小虎博客就来把相应的方法写下来,以备以后的查看。

第一:首先需要在根目录下新建一个 php 程序文件,比如我们命名为 single.php,这个 single.php 是自定义的页面,然后写入如下的 PHP 代码:

[code lang="php"]
<?php
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
if ((DEBUG_MODE &
2) != 2)
{$smarty->caching = true;}
/* 清除缓存
*/
clear_cache_files();
//引用模板
if (!$smarty->is_cached('single.dwt', $cache_id)){
assign_template();
//红色区是单页面需要调用到的数据,需要哪一部分就将其引用进来。
$position =
assign_ur_here();
$smarty->assign('page_title',
$position['title']); // 页面标题
$smarty->assign('ur_here',
$position['ur_here']); // 当前位置
/* meta information */
$smarty->assign('keywords',
htmlspecialchars($_CFG['shop_keywords']));
$smarty->assign('description',
htmlspecialchars($_CFG['shop_desc']));
$smarty->assign('helps', get_shop_help()); //网店帮助
}
$smarty->display('single.dwt',
$cache_id);
?>
[/code]

第二:相应的在模板文件夹里面创建 single.dwt 文件,single.dwt要跟 single.php 页面一致,因为在上面的模板代码

[code lang="php"]
$smarty->display('single.dwt',$cache_id);
[/code]

里面引用了 single.dwt,新建好 single.dwt 后写入如下代码:

[code lang="php"]
<!DOCTYPE
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta
http-equiv="Content-Type" content="text/html; charset=GBK" />
<meta
name="Keywords" content="{$keywords}" />
<meta name="Description"
content="{$description}" />
<!-- TemplateBeginEditable name="doctitle"-->
<title>68ecshop</title>
<!-- TemplateEndEditable-->
<!-- TemplateBeginEditable name="head" -->
<!--TemplateEndEditable -->
<link rel="shortcut icon" href="favicon.ico"/>
<link rel="icon" href="animated_favicon.gif" type="image/gif"/>
<link href="{$ecs_css_path}" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- #BeginLibraryItem "/library/page_header.lbi" --><!-- #EndLibraryItem -->
<div class="wrapper">
<div id="ur_here">
<!--#BeginLibraryItem "/library/ur_here.lbi" --><!-- #EndLibraryItem-->
</div>
把你创建的html里面的html内容复制放在这里
</div>
<!--#BeginLibraryItem "/library/page_footer.lbi" --><!-- #EndLibraryItem-->
</body>
</html>
[/code]

第三:OK,现在的程序与模板文件都已经建立了,我们还要修改一个文件,就是单页面必须要有的“当前位置”这个文件的存在,位置如 /library/ur_here.lbi,那么就需要修改以下两个文件的代码。

【1】找到includes/lib_main.php文件,修改,找到代码155行起.

[code lang="php"]
/*初始化“页面标题”和“当前位置” */
/* 积分兑换 */
elseif
('exchange' == $filename)
{
$page_title =
$GLOBALS['_LANG']['exchange'] . '_' . $page_title;
$args
= array('wsid' => '0');
$ur_here .= '
<code>></code> <a href="exchange.php">' .
$GLOBALS['_LANG']['exchange'] . '</a>';
}
/* 其他的在这里补充 */
[/code]

在积分兑换下面新增:

[code lang="php"]
/* 新增单页面 */
elseif ('single' == $filename){
$page_title
= $GLOBALS['_LANG']['single'] . '_' . $page_title;
$ur_here
.= ' <code>></code> <a href="single.php">' .
$GLOBALS['_LANG']['single'] . '</a>';
}
[/code]

【2】找到语言包languages/zh_cn/common.php 在最尾部加上代码:

[code lang="php"]
/* 新增单页面语言项
*/
$_LANG['single'] = '新增单页面';
[/code]

这样通过前台访问single.php就可以显示你的页面内容了,而且头部和尾部都是调用的!

标签:

给我留言