请问前台怎么通过循环直接调用友情链接?

  • 时间:
  • 浏览:3711
  • 来源:MIP建站系统交流平台

请问前台怎么通过循环直接调用友情链接?而不是通过钩子的方式调用。我修改过插件上的HTML文件内容,但是只要一加上判断就全部是空内容。根本无法自定义样式修改

1个回答

第一步:将友情链接插件里面的代码,搬运到 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}

您尚未登录,暂无法回复!请先 登录/注册