知识学习

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 2628|回复: 0

destoon自定义函数获取分类名称,地区名称,几天前时间,...

[复制链接]

升级   100%

152

主题

0

回帖

752

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
752
发表于 2020-9-16 00:04:32 | 显示全部楼层 |阅读模式
需要在api/extend.func.php 文件中加入的函数

1、获取分类名称 cat_name($catid) 传入分类id
  1. function cat_name($catid) {
  2. global $db;
  3. $catid = intval($catid);
  4. $catname = '';
  5.     $r = $db->get_one("SELEC<span style="box-sizing: border-box; word-break: break-all; text-size-adjust: none;">t catname FROM {$db->pre}category WHER<span style="box-sizing: border-box; word-break: break-all; text-size-adjust: none;">e catid=$catid");
  6.     $catname = $r['catname'];
  7. return $catname;
  8. }</span></span>
复制代码



2、获取地区名称 area_name($areaid) 传入地区id
  1. function area_name($areaid) {
  2. global $db;
  3. $catid = intval($areaid);
  4. $areaname = '';
  5.     $r = $db->get_one("SELEC<span style="box-sizing: border-box; word-break: break-all; text-size-adjust: none;">t areaid,areaname FROM {$db->pre}area WHER<span style="box-sizing: border-box; word-break: break-all; text-size-adjust: none;">e areaid=$areaid");
  6.     $areaname = $r['areaname'];
  7. return $areaname ? :'全国';
  8. }</span></span>
复制代码


3、时间格式化 比如几天前 gl_format_date($time)
  1. <p style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; color: rgb(51, 51, 51); font-family: " microsoft="" yahei",="" "hanhei="" sc",="" pinghei,="" "pingfang="" "helvetica="" neue",="" helvetica,="" arial,="" "hiragino="" sans="" gb",="" "heiti="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-size:="" 16px;"=""><span style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; color: rgb(47, 156, 10); font-family: Verdana, Arial; line-height: 21px; background-color: rgb(253, 253, 253);">//时间格式化 传入时间戳格式1464662723</span></p><p style="box-sizing: border-box; word-break: break-all; text-size-adjust: none; color: rgb(51, 51, 51); font-family: " microsoft="" yahei",="" "hanhei="" sc",="" pinghei,="" "pingfang="" "helvetica="" neue",="" helvetica,="" arial,="" "hiragino="" sans="" gb",="" "heiti="" "wenquanyi="" micro="" hei",="" sans-serif;="" font-size:="" 16px;"="">function gl_format_date($time){
  2.     $t=time()-$time;
  3.     $f=array(
  4.         '31536000'=>'年',
  5.         '2592000'=>'个月',
  6.         '604800'=>'星期',
  7.         '86400'=>'天',
  8.         '3600'=>'小时',
  9.         '60'=>'分钟',
  10.         '1'=>'秒'
  11.     );
  12.     foreach ($f as $k=>$v)    {
  13.         if (0 !=$c=floor($t/(int)$k)) {
  14.             return $c.$v.'前';
  15.         }
  16.     }
  17. };
  18. </p>
复制代码

4、获取评论数 gl_get_comments($mid,$itemid)   
  1. function gl_get_comments($mid,$itemid) {
  2. global $db;
  3. $nums = $db->get_one("SELEC<span style="box-sizing: border-box; word-break: break-all; text-size-adjust: none;">t COUNT(*) AS num FROM {$db->pre}comment WHER<span style="box-sizing: border-box; word-break: break-all; text-size-adjust: none;">e item_mid='$mid' and item_id='$itemid'");
  4. return $nums['num'] ;
  5. }</span></span>
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|知识学习 ( 鲁ICP备20015483号 )

GMT+8, 2026-5-13 21:57 , Processed in 0.063783 second(s), 24 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表