首先在最底层source\class\table写入底层安全调用文件例如:table_common_friendlink.php
代码:
<?php /**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: table_common_friendlink.php 27449 2012-02-01 05:32:35Z zhangguosheng $
*/ if(!defined('IN_DISCUZ')) {
exit('Access Denied');
} class table_common_friendlink extends discuz_table
{
public function __construct() { $this->_table = 'common_friendlink';
$this->_pk = 'id'; parent::__construct();
} public function fetch_all_by_displayorder($type = '')
{
$args = array($this->_table);
if($type) {
$sql = 'WHERE (`type` & %s > 0)';
$args[] = $type;
}
return DB::fetch_all("SELECT * FROM %t $sql ORDER BY displayorder", $args, $this->_pk);
} public function fetch_all_by_sql($where, $order = '', $start = 0, $limit = 0, $count = 0, $alias = '') {
$where = $where && !is_array($where) ? " WHERE $where" : '';
if(is_array($order)) {
$order = '';
}
if($count) {
return DB::result_first('SELECT count(*) FROM '.DB::table($this->_table).' %i %i %i '.DB::limit($start, $limit), array($alias, $where, $order));
}
return DB::fetch_all('SELECT * FROM '.DB::table($this->_table).' %i %i %i '.DB::limit($start, $limit), array($alias, $where, $order));
} } ?>
然后前台source\module\portal调用查询文件:portal_index.php
代码:
<?php if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
include_once libfile('function/portalcp'); //此处可不用。 //discuz 万能SQL查询调用语句写法
$wheresqla = " type=2 ";
$ordera = " ORDER BY id ASC ";
$linksa = C::t('common_friendlink') -> fetch_all_by_sql($wheresqla, $ordera, 0, 20); include_once template('diy:portal/index');
?>
模板处template\default\portal调用文件:portalcp_index.htm
代码:
<section class="wp d_friendlinks mtw">
<div class="d_friendlinksbg"></div>
<div class="d_friendlinksa">
<!--{loop $linksa $value}-->
<a href="http://www.juhutang.com/ $value[url]" target="_blank">$value[name]</a>
<!--{/loop}-->
</div>
</section>