如何调用合作伙伴至首页

发布时间:2019-08-12点击数:78

首先,以默认模板为例就是在“theme/default/inc”目录下新建文件名为“..from_theme.php”的PHP文件,里面内容包含

if (!defined('IN_DOUCO')) {

    die('Hacking attempt');

}

 

/**

 * +----------------------------------------------------------

 * 获取合作伙伴列表

 * +----------------------------------------------------------

 */

if ($_MODULE['open']['partner']) {

    $smarty->assign('recommend_partner', get_partner_list());

}

function get_partner_list() {

    $sql = "SELECT * FROM " . $GLOBALS['dou']->table('partner') . " ORDER BY sort DESC, id DESC LIMIT 12";

    $query = $GLOBALS['dou']->query($sql);

    while ($row = $GLOBALS['dou']->fetch_array($query)) {

        $partner_list[] = array (

                "id" => $row['id'],

                "name" => $row['name'],

                "image" => $GLOBALS['dou']->dou_file($row['image']),

                "url" => $row['url']

        );

    }

 

    return $partner_list;

}

 

然后在相同目录下新建文件“recommend_partner.tpl”,内容为

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<div class="recProduct">

 <h3><em>合作伙伴</em><a href="{$url.partner}" class="more">更多</a></h3>

 <div class="list">

  <!-- {foreach from=$recommend_partner name=recommend_partner item=partner} -->

  <dl{if $smarty.foreach.recommend_partner.iteration % 4 eq 0} class="noMargin"{/if}>

   <dd class="img"><a href="{$partner.url}"><img src="{$partner.image}" /></a></dd>

   <dt><a href="{$partner.url}">{$partner.name}</a></dt>

  </dl>

  <!-- {/foreach} -->

 </div>

</div>

 

最后在“theme/default/index.dwt”里增加以下代码即可

{include file="inc/recommend_partner.tpl"}