首页静态页面生成后,我们接下来要生成的是产品类别的静态页面,我的想法是把产品类别页面保存在跟目录下,这样虽然会比较乱,
但是比较适合优化,因为一般搜索引擎抓取的时候只抓取二到三层。把产品类别放在根目录,体现产品类别的重要性,易于搜索引擎的
抓取,另外一方面,我们可以把产品放在下个目录中。
类似代码:
$filename = build_uri('category', array('cid' => $catinfo['cat_id']));//构造路径,这个可以选择自己喜欢的构造方法
$content = $GLOBALS['smarty']->make_html('category.dwt');//产生静态页面内容
$filename = ROOT_PATH . $filename;//生成文件路径,在根目录下
file_put_contents($filename, $content);//输出
产品的静态页面代码:
$goodinfo = get_all_goodsinfo($goods_id);
$cat_name = $goodinfo['cat_name'];
$goodsfile = build_uri('goods', array('gid' => $goods_id));
$content = $GLOBALS['smarty']->make_html('goods.dwt');
$html_tempdir = (ROOT_PATH.$cat_name.'/');
if (!is_dir($html_tempdir))//生成产品目录
{
mkdir($html_tempdir);
}
$htmlfilename = ROOT_PATH . $goodsfile;
file_put_contents($htmlfilename,$content);
我的是使用类别名称加下划线:
function build_uri(........)
................
case 'category':
$cat_name = $GLOBALS['db']->getOne('SELECT cat_name FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$cid'");
$uri = $cat_name . '-' . $cid;
if (!empty($page))
{
$uri .= '-' . $page;
}
........
case 'goods':
$goods_info = $GLOBALS['db']->getRow('SELECT g.goods_name, c.cat_name FROM ' . $GLOBALS['ecs']->table('goods') . " as g left join " .
$GLOBALS['ecs']->table('category') . " as c on c.cat_id = g.cat_id WHERE g.goods_id = '$gid'");
$goods_name = $goods_info['goods_name'];
$cat_name = $cat_name;
$uri = $cat_name . '/' . $goods_name . '-' . $gid ;
..........................
参考网站:airmax 87,airmax 180,airmax tn