SMF论坛模板用sql语句自定义调用数据

首先在需要调用数据的那个方法里面添加全局变量 $smcFunc
如:
[code]
global $context, $settings, $options, $txt, $scripturl, $modSettings,$smcFunc;
[/code]
调用方法:

[code]
echo ‘
<ul class="top_con">’;
$request = $smcFunc[‘db_query’](”, ‘SELECT m.id_topic,m.subject FROM {db_prefix}topics as t inner join {db_prefix}messages as m ON t.id_first_msg = m.id_msg where t.id_board not in(14,16,21) order by t.id_topic desc LIMIT 9’);//sql
while($a = $smcFunc[‘db_fetch_assoc’]($request)) {
echo "<li><a href=’index.php?topic=".$a[‘id_topic’].".0′ title=’".$a[‘subject’]."’>".$a[‘subject’]."</a></li>";//输出
}
$smcFunc[‘db_free_result’]($request);//释放sql
echo’
</ul>
[/code]
我这里是在首页上面自定义输出我需要的文章。

下面是我自定义输出的幻灯。其实都差不多:

[code]
echo ‘
<ul>’;
$request = $smcFunc[‘db_query’](”, ‘SELECT t.id_topic,t.indexhdurl FROM {db_prefix}topics as t where t.indexhd = 1 order by t.indextime desc LIMIT 4’);
while($a = $smcFunc[‘db_fetch_assoc’]($request)) {
echo "<li><a href=’index.php?topic=".$a[‘id_topic’].".0′><img src=’http://www.XXX.com/upload/smfhd/".$a[‘indexhdurl’]."’ width=’321px’ height=’228px’/></a></li>";
}
$smcFunc[‘db_free_result’]($request);
echo’
</ul>
[/code]

效果图: