取得某模板某库设置的数量。 精品推荐 热销商品

2016-07-07 15:16 来源:www.chinab4c.com 作者:ecshop专家

/**
* 取得某模板某库设置的数量
* @paramstring$template模板名,如index
* @paramstring$library 库名,如recommend_best
* @paramint$def_num 默认数量:如果没有设置模板,显示的数量
* @returnint数量
*/
function get_library_number($library, $template = null)
{
if (empty($template))
{
$template = basename(PHP_SELF);
$template = substr($template, 0, strrpos($template, '.'));
}
$template = addslashes($template);

static $lib_list = array();

/* 如果没有该模板的信息,取得该模板的信息 */
if (!isset($lib_list[$template]))
{
$lib_list[$template] = array();
$sql = "SELECT library, number FROM " . $GLOBALS['ecs']->table('template') .
" WHERE theme = '" . $GLOBALS['_CFG']['template'] . "'" .
" AND filename = '$template' AND remarks='' ";
$res = $GLOBALS['db']->query($sql);
while ($row = $GLOBALS['db']->fetchRow($res))
{
$lib = basename(strtolower(substr($row['library'], 0, strpos($row['library'], '.'))));
$lib_list[$template][$lib] = $row['number'];
}
}

$num = 0;
if (isset($lib_list[$template][$library]))
{
$num = intval($lib_list[$template][$library]);
}
else
{
/* 模板设置文件查找默认值 */
include_once(ROOT_PATH . 'admin/includes/lib_template.php');
static $static_page_libs = null;
if ($static_page_libs == null)
{
$static_page_libs = $page_libs;
}
$lib = '/library/' . $library . '.lbi';

$num = isset($static_page_libs[$template][$lib]) ? $static_page_libs[$template][$lib] :4;
}

return $num;
}

lib_main.php

回答:
不太清楚,你帮顶了!








服装论坛www.zgfzr.com