1 Star 0 Fork 0

ChasingWorld/Typecho响应式主题-Hymer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
functions.php 4.83 KB
一键复制 编辑 原始数据 按行查看 历史
程序员墨鱼 提交于 2020-12-08 15:42 . 增加轮播图编辑功能
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
function themeConfig($form) {
$logoUrl = new Typecho_Widget_Helper_Form_Element_Text('logoUrl', NULL, NULL, _t('站点 LOGO 地址'), _t('在这里填入一个图片 URL 地址, 以在网站标题前加上一个 LOGO'));
$form->addInput($logoUrl);
$sidebarBlock = new Typecho_Widget_Helper_Form_Element_Checkbox('sidebarBlock',
array('ShowRecentPosts' => _t('显示最新文章'),
'ShowRecentComments' => _t('显示最近回复'),
'ShowCategory' => _t('显示分类'),
'ShowArchive' => _t('显示归档'),
'ShowOther' => _t('显示其它杂项')),
array('ShowRecentPosts', 'ShowRecentComments', 'ShowCategory', 'ShowArchive', 'ShowOther'), _t('侧边栏显示'));
$form->addInput($sidebarBlock->multiMode());
}
function themeFields($layout) {
$logoUrl = new Typecho_Widget_Helper_Form_Element_Text(
'logoUrl',
NULL,
NULL,
_t('文章主图'),
_t('在这里填入一个图片URL地址, 作为文章的主图')
);
$layout->addItem($logoUrl);
$recommend = new Typecho_Widget_Helper_Form_Element_Text(
'recommend',
NULL,
NULL,
_t('推荐'),
_t('1代表推荐')
);
$layout->addItem($recommend);
$recommend = new Typecho_Widget_Helper_Form_Element_Text(
'swiper',
NULL,
NULL,
_t('首页轮播图'),
_t('这里填写图片地址')
);
$layout->addItem($recommend);
}
/**
* 根据文章的自定义字段 recommend 来筛选推荐的文章
* Class Widget_Post_Recommend
*/
class Widget_Post_Recommend extends Widget_Abstract_Contents
{
public function __construct($request, $response, $params = NULL)
{
parent::__construct($request, $response, $params);
$this->parameter->setDefault(
array(
'pageSize' => empty($this->parameter->pageSize) ? 5 : $this->parameter->pageSize,
'parentId' => 0,
'ignoreAuthor' => false
)
);
}
public function execute()
{
$query = $this->db->select()->from('table.fields')
->where('table.fields.name = ?', 'recommend')
->where('table.fields.str_value = ?', '1');
$results = $this->db->fetchAll($query);
$ids = [0];
foreach ($results as $result) {
$ids []= $result['cid'];
}
$query = $this->db->select()->from('table.contents')
->where('cid in ?', $ids)
->where('table.contents.status in ?', ['publish', 'hidden'])
->order('modified', Typecho_Db::SORT_DESC)
->limit($this->parameter->pageSize);
$this->db->fetchAll($query, array($this, 'push'));
}
}
/**
* 根据独立页面的自定义字段 showInNav 来筛选页面
* Class Widget_Page_ShowInNav
*/
class Widget_Page_ShowInNav extends Widget_Abstract_Contents
{
public function __construct($request, $response, $params = NULL)
{
parent::__construct($request, $response, $params);
}
public function execute()
{
$query = $this->db->select()->from('table.fields')
->where('table.fields.name = ?', 'showInNav')
->where('table.fields.str_value = ?', '1');
$results = $this->db->fetchAll($query);
$ids = [0];
foreach ($results as $result) {
$ids []= $result['cid'];
}
$query = $this->db->select()->from('table.contents')
->where('cid in ?', $ids)
->where('table.contents.type = ?', 'page');
$this->db->fetchAll($query, array($this, 'push'));
}
}
/**
* 根据文章的自定义字段 swiper 来筛选轮播图的文章
* Class Widget_Post_Swiper
*/
class Widget_Post_Swiper extends Widget_Abstract_Contents
{
public function __construct($request, $response, $params = NULL)
{
parent::__construct($request, $response, $params);
$this->parameter->setDefault(
array(
'pageSize' => empty($this->parameter->pageSize) ? 5 : $this->parameter->pageSize,
'parentId' => 0,
'ignoreAuthor' => false
)
);
}
public function execute()
{
$query = $this->db->select()->from('table.fields')
->where('table.fields.name = ?', 'swiper')
->where('table.fields.str_value != ?', '');
$results = $this->db->fetchAll($query);
$ids = [0];
foreach ($results as $result) {
$ids []= $result['cid'];
}
$query = $this->db->select()->from('table.contents')
->where('cid in ?', $ids)
->where('table.contents.status in ?', ['publish', 'hidden'])
->order('modified', Typecho_Db::SORT_DESC)
->limit($this->parameter->pageSize);
$this->db->fetchAll($query, array($this, 'push'));
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chasingworld/typecho-theme-hymer.git
git@gitee.com:chasingworld/typecho-theme-hymer.git
chasingworld
typecho-theme-hymer
Typecho响应式主题-Hymer
master

搜索帮助