第一步:将友情链接插件里面的代码,搬运到 all/mip/Mip.php中,进行全局赋值
代码如下:
$friendLink = db('Friendlink')->order('sort ASC')->select();
$friendLink['friendLinkAll'] = false;
$friendLink['friendLinkIndex'] = false;
$friendLink['friendLinkNotIndex'] = false;
foreach ($friendLink as $key => $val) {
if ($val['type'] == 'all') {
$friendLink['friendLinkAll'] = true;
}
if ($val['type'] == 'index') {
$friendLink['friendLinkIndex'] = true;
}
if ($val['type'] == 'notIndex') {
$friendLink['friendLinkNotIndex'] = true;
}
}
$this->assign('friendLink',$friendLink);
第二步:将钩子中渲染的html代码,直接拿到模板中即可。
代码如下:
{if condition='$friendLink.friendLinkAll || $friendLink.friendLinkNotIndex || $friendLink.friendLinkIndex'}
<div class="friend-link hidden-xs">
<ul>
{if condition='$ctr == "Index"'}
{if condition='$friendLink.friendLinkAll || $friendLink.friendLinkIndex'}
<li> 友情链接:</li>
{/if}
{else/}
{if condition='$friendLink.friendLinkAll || $friendLink.friendLinkNotIndex'}
<li> 友情链接:</li>
{/if}
{/if}
{foreach name='$friendLink' id='v'}
{if condition='$ctr == "Index"'}
{if condition='$v["type"] == "all" || $v["type"] == "index"'}
<li>
<a href="{$v['url']}" data-type="mip" data-title="{$v['description']?$v['description']:$v['name']}" title="{$v['description']?$v['description']:$v['name']}" target="_blank">{$v['name']}</a>
</li>
{/if}
{else/}
{if condition='$v["type"] == "all" || $v["type"] == "notIndex"'}
<li>
<a href="{$v['url']}" data-type="mip" data-title="{$v['description']?$v['description']:$v['name']}" title="{$v['description']?$v['description']:$v['name']}" target="_blank">{$v['name']}</a>
</li>
{/if}
{/if}
{/foreach}
</ul>
</div>
{/if}