Skip to content

Commit

Permalink
如果没有设置type时,才使用全局配置
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangmitiao committed Oct 9, 2022
1 parent 3b2f2bb commit 89cc094
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion usr/themes/default/sidebar.php
Expand Up @@ -35,7 +35,7 @@
<section class="widget">
<h3 class="widget-title"><?php _e('归档'); ?></h3>
<ul class="widget-list">
<?php \Widget\Contents\Post\Date::alloc('type=month&format=F Y')
<?php \Widget\Contents\Post\Date::alloc()
->parse('<li><a href="{permalink}">{date}</a></li>'); ?>
</ul>
</section>
Expand Down
25 changes: 12 additions & 13 deletions var/Widget/Contents/Post/Date.php
Expand Up @@ -21,13 +21,6 @@
*/
class Date extends Base
{
/**
* @param Config $parameter
*/
protected function initParameter(Config $parameter)
{
$parameter->setDefault('format=Y-m&type=month&limit=0');
}

/**
* 初始化函数
Expand All @@ -36,18 +29,24 @@ protected function initParameter(Config $parameter)
*/
public function execute()
{
var_dump(isset($this->options->postArchiveType));
if (isset($this->options->postArchiveType)) {
// 在开发主题时,type和format应该同时设置
// 如果没有设置type,则以全局选项为准
// 未来如有需要,可在全局选项中单独设置format和limit
if (!isset($this->parameter->type)) {
switch ($this->options->postArchiveType) {
case 'year':
$this->parameter->setDefault('format=Y&type=year', true);
$this->parameter->setDefault('format=Y&type=year&limit=0', true);
break;
case 'month':
$this->parameter->setDefault('format=F Y&type=month', true);
$this->parameter->setDefault('format=F Y&type=month&limit=0', true);
break;
default:
$this->parameter->setDefault('format=Y-m&type=month&limit=0', true);
}
} else {
/** 设置参数默认值 */
$this->parameter->setDefault('format=Y-m&type=month&limit=0');
}
/** 设置参数默认值 */
$this->parameter->setDefault('format=Y-m&type=month&limit=0');

$resource = $this->db->query($this->db->select('created')->from('table.contents')
->where('type = ?', 'post')
Expand Down

0 comments on commit 89cc094

Please sign in to comment.