zoukankan      html  css  js  c++  java
  • dede中arcurl的解析

    有时候我们需要在dede中通过$dsql查询出文章数据,并生成文章的地址。
    但是dede默认的dede_archives和附加表dede_addonarticle都没有存放arcurl的字段。
    说明arcurl是动态生成的,通过/include/helpers/channelunit.helper.php文件中的GetFileUrl函数来获取的。
     
    例如:
    <?php
    require_once (dirname(__FILE__) . "/include/common.inc.php");
    
    $siteUrl = 'http://www.xxx.com';
    
    //我们获取所有文章数据
    $sql = 'SELECT arc.*, tp.typedir, tp.typename, tp.corank, tp.isdefault, tp.defaultname, tp.namerule, tp.moresite, tp.siteurl, tp.sitepath FROM `#@__archives` AS arc LEFT JOIN `#@__arctype` AS tp ON arc.typeid=tp.id WHERE arc.ismake=1 AND arc.arcrank=0 ORDER BY arc.id';
    $dsql->Execute('me', $sql);
    
    while($row = $dsql->GetArray('me')) {
        $artUrl = $siteUrl . GetFileUrl($row['id'], $row['typeid'], $row['senddate'], $row['title'], $row['ismake'], $row['arcrank'], $row['namerule'], $row['typedir'], $row['money'], $row['filename'], $row['moresite'], $row['siteurl'], $row['sitepath']);
        echo '<a href="' . $artUrl . '">' . $row['title'] . '</a>';
    }
    
    通过GetFileUrl函数我们就可以获取到文章的地址。

    当我们使用dede的loop标签时,该标签不支持[field:arcurl/],这时候我们只能创建自定义一个函数来获取文章链接。
    在include/extend.func.php下面添加我们自定义的函数,如下:
    function getArtUrl($arcId) { 
        global $dsql; 
        $sql = "SELECT arc.*, tp.typedir, tp.typename, tp.corank, tp.isdefault, tp.defaultname, tp.namerule, tp.moresite, tp.siteurl, tp.sitepath FROM `#@__archives` AS arc LEFT JOIN `#@__arctype` AS tp ON arc.typeid=tp.id WHERE arc.id={$arcId}"; 
        $row = $dsql->GetOne($sql); 
        $artUrl = GetFileUrl($row['id'], $row['typeid'], $row['senddate'], $row['title'], $row['ismake'], $row['arcrank'], $row['namerule'], $row['typedir'], $row['money'], $row['filename'], $row['moresite'], $row['siteurl'], $row['sitepath']);
        return $artUrl; 
    }
    
    {dede:loop table='#@__archives' sort='' row='4' if=''}
        <a href="[field:id function='getArtUrl(@me)'/]">[field:title function='cn_substr(@me,42)'/]</a>
    {/dede:loop}
    
  • 相关阅读:
    Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C 倒序并查集
    hdu 5573 Binary Tree 构造
    hdu 5514 Frogs 容斥思想+gcd 银牌题
    hdu 5536 Chip Factory 字典树+bitset 铜牌题
    LA 7263 Today Is a Rainy Day bfs+暴力 银牌题
    hdu 5834 Magic boy Bi Luo with his excited tree 树形dp+转移
    hdu 5869 Different GCD Subarray Query BIT+GCD 2016ICPC 大连网络赛
    LA 7043 International Collegiate Routing Contest 路由表 字典树离散化+bitset 银牌题
    校验注解工具类
    java-创建对象实例
  • 原文地址:https://www.cnblogs.com/jkko123/p/6294600.html
Copyright © 2011-2022 走看看