emlog友情链接分类管理的实现
[ 2017/04/03, Emlog , 5996阅, 1评 ]

emlog友情链接分类管理,基于emlog5.3.1

友链分类管理1.png

友链分类管理2.png

功能如上图所示,文件代码等在文末。

1.数据库改动

a.添加表表前缀_sortlink

CREATE TABLE `表前缀_sortlink` (
  `linksort_id` int(10) NOT NULL AUTO_INCREMENT,
  `linksort_name` varchar(30) NOT NULL,
  `taxis` int(10) UNSIGNED NOT NULL DEFAULT '0',
  primary key (`linksort_id`)
) ENGINE=MyISAM;

b.在原有的表前缀_link表中增加字段linksortid

ALTER TABLE `表前缀_link` ADD `linksortid` INT(10) NOT NULL AFTER `id`;

2.添加文件

admin/sortlink.php
admin/views/sortlink.php
admin/views/sortlinkedit.php
include/model/sortlink_model.php

3.修改文件

admin/link.php
admin/views/header.php
admin/views/links.php
admin/views/linkedit.php
include/model/link_model.php
include/lib/cache.php

4.前台调用方法

a.获取所有链接分类

<?php
function getLinkSort(){
  global $CACHE;
  $sortlink_cache = $CACHE->readCache('sortlink'); ?>
  <?php foreach($sortlink_cache as $value):?>
<li sid="<?php echo $value['linksort_id']; ?>"><?php echo $value['linksort_name']; ?></li>
  <?php endforeach; ?>
<?php }?>

b.按分类显示链接

<?php
function sortLinks(){
  $db = MySql::getInstance();
  global $CACHE;
  $sortlink_cache = $CACHE->readCache('sortlink');
  foreach($sortlink_cache as $value){
    $out .= '<dl id="item'.$value['linksort_id'].'"><dt>'.$sortlink_cache[$value['linksort_id']]['linksort_name'].'</dt><ul>';
    $links = $db->query ("SELECT * FROM ".DB_PREFIX."link WHERE linksortid='$value[linksort_id]' AND hide='n' order by id DESC");
    while ($row = $db->fetch_array($links)){
      $out .='<li><a href="'.$row['siteurl'].'" title="'.$row['description'].'" target="_blank">'.$row['sitename'].'</a></li>';
    }
    $out .='</ul></dl>';
  }
  echo $out;
}?>

c.获取指定分类链接

<?php
function getOneSortLink($num) {
  $db = MySql::getInstance();
  $sql = "SELECT * FROM ".DB_PREFIX."link WHERE linksortid='1' and hide='n' LIMIT 0,$num";
  $list = $db->query($sql);
  while($row = $db->fetch_array($list)){ ?>
  <a href="<?php echo $row['siteurl']; ?>" target="_blank"><?php echo $row['sitename']; ?></a>
<?php } ?>
<?php } ?>

d.其他使用方式可按需发掘

5.代码托管于Gitee

https://gitee.com/jianggle/emlog-DIY/tree/master/rootlinks

有朋自远方来...评论一下呗O(∩_∩)O

  • 评论(1)

    Harry [ 回复 ]
    2019-01-14 18:48

    好用❤