├── README.md └── Plugin.php /README.md: -------------------------------------------------------------------------------- 1 | # typechoSticky 2 | **Typecho 文章置顶插件。支持分类置顶。** 3 | 4 | 原作者: http://kan.willin.org/typecho/ (网站不可访问) ,已经停止更新了。在Github也没有找到源码,于是重新修改上传了一份。 5 | 6 | 重新修改增加了 分类文章置顶、单独分类文章置顶的功能。 7 | 优化了一下原有默认[置顶]的CSS风格 8 | 9 | ### 使用方法 10 | 下载解压至 ** usr/plugins ** 目录,文件夹重命名为:**Sticky** 11 | 12 | 代码很简单,修改的话,也有相应的注释。 13 | 14 | ### 最终样式 15 | ![置顶风格](http://og5z0vu2y.bkt.clouddn.com/typecho/typechozd.jpg) 16 | 17 | 如须显示,加一段代码在 article 后面 18 | 19 | 类似
20 | `
sticky() ?>` 21 | 22 | 记得在首页(index.php)和(archive.php)页都加上 23 | -------------------------------------------------------------------------------- /Plugin.php: -------------------------------------------------------------------------------- 1 | indexHandle = array('Sticky_Plugin', 'sticky'); 27 | Typecho_Plugin::factory('Widget_Archive')->categoryHandle = array('Sticky_Plugin', 'sticky'); 28 | } 29 | 30 | /** 31 | * 禁用插件方法,如果禁用失败,直接抛出异常 32 | * 33 | * @static 34 | * @access public 35 | * @return void 36 | * @throws Typecho_Plugin_Exception 37 | */ 38 | public static function deactivate(){} 39 | 40 | /** 41 | * 获取插件配置面板 42 | * 43 | * @access public 44 | * @param Typecho_Widget_Helper_Form $form 配置面板 45 | * @return void 46 | */ 47 | public static function config(Typecho_Widget_Helper_Form $form) 48 | { 49 | $sticky_cids = new Typecho_Widget_Helper_Form_Element_Text( 50 | 'sticky_cids', NULL, '', 51 | '置顶文章的 cid', '按照排序输入, 请以半角逗号或空格分隔 cid.'); 52 | $form->addInput($sticky_cids); 53 | 54 | $sticky_html = new Typecho_Widget_Helper_Form_Element_Textarea( 55 | 'sticky_html', NULL, "[置顶] ", 56 | '置顶标题的 html', '
在 index.php 的 $this->title(); 前面加上 $this->sticky(); 可出现这段 html. 57 |
例: <h2 class="title"><a href="<?php $this->permalink() ?>"><?php $this->sticky(); $this->title() ?></a></h2>
'); 58 | $sticky_html->input->setAttribute('rows', '7')->setAttribute('cols', '80'); 59 | $form->addInput($sticky_html); 60 | 61 | } 62 | 63 | /** 64 | * 个人用户的配置面板 65 | * 66 | * @access public 67 | * @param Typecho_Widget_Helper_Form $form 68 | * @return void 69 | */ 70 | public static function personalConfig(Typecho_Widget_Helper_Form $form){} 71 | 72 | /** 73 | * 选取置顶文章 74 | * 75 | * @access public 76 | * @param object $archive, $select 77 | * @return void 78 | */ 79 | public static function sticky($archive, $select) 80 | { 81 | $config = Typecho_Widget::widget('Widget_Options')->plugin('Sticky'); 82 | $sticky_cids = $config->sticky_cids ? explode(',', strtr($config->sticky_cids, ' ', ',')) : ''; 83 | if (!$sticky_cids) return; 84 | 85 | $db = Typecho_Db::get(); 86 | // $paded = $archive->request->get('page',1); //单独首页置顶 87 | $sticky_html = $config->sticky_html ? $config->sticky_html : "[置顶] "; 88 | 89 | foreach($sticky_cids as $cid) { 90 | if ($cid && $sticky_post = $db->fetchRow($archive->select()->where('cid = ?', $cid))) { 91 | // if ($paded == 1) { // 首頁 page.1 才會有置頂文章 92 | $sticky_post['sticky'] = $sticky_html; 93 | $archive->push($sticky_post); // 選取置頂的文章先壓入 94 | // } 95 | $select->where('table.contents.cid != ?', $cid); // 使文章不重覆 96 | } 97 | } 98 | } 99 | 100 | } 101 | --------------------------------------------------------------------------------