Skip to content

Commit

Permalink
时间戳计算微调
Browse files Browse the repository at this point in the history
  • Loading branch information
webersongao committed Mar 12, 2024
1 parent 292b511 commit b5d7424
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion microblog/includes/microblog-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function microblog_post_title_listdate_input() {
<label class="microblog-admin-option-label">
<input type='radio' name='microblog_setting_data[mb_date_format]' value='<?php echo esc_attr('date_format_notime'); ?>' <?php checked($value, 'date_format_notime'); ?> />
不显示时间
<!--echo date_i18n('m-d H:i', time());-->
<!--echo date_i18n('m-d H:i', current_time('timestamp'));-->
</label>
<label class="microblog-admin-option-label">
<input type='radio' name='microblog_setting_data[mb_date_format]' value='<?php echo esc_attr('date_format_date'); ?>' <?php checked($value, 'date_format_date'); ?> />
Expand Down
13 changes: 5 additions & 8 deletions microblog/includes/microblog-index.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ function customize_main_query($query) {
}

if ($query->get('post_type') === 'micropost') {
// $page_num = isset($options['mb_postrss_num']) ? intval($options['mb_postrss_num']) : 10;
$page_num = 10;//
$feed_num = get_option('posts_per_rss'); // 获取“Feed 中显示最近”的数量
$page_num = $feed_num ? intval($feed_num) : 10;
$query->set('posts_per_rss', $page_num);
} else {
if ($feed_miropost){
if (!is_post_type_archive('micropost')){
$query->set('post_type', array('post', 'micropost'));
}
// 仅在全站Feed中格式化输出
add_filter('the_title', 'formart_microblog_feed_title', 10, 2);
}
}
Expand All @@ -58,14 +57,12 @@ function microblog_plugin_data_activation() {
$options = get_option('microblog_setting_data');
if (empty($options)) {
$defaults = array(
'mb_title_show' => true, // 默认为显示标题
'mb_date_show' => true, // 默认为显示日期
'mb_date_format' => 'date_format_date', // 时间格式 跟随站点->日期设置项
'mb_title_position' => array('titlebottom'), // 默认标题位置为 titlebottom
'mb_title_show' => true,
'mb_date_format' => 'date_format_vague',
'mb_title_position' => array('titlebottom'),
);
add_option('microblog_setting_data', $defaults);
}
// 刷新重写规则
microblog_rewrite_flush();
}

Expand Down
9 changes: 2 additions & 7 deletions microblog/includes/micropost-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function update_global_microblog_option($new_value) {


function micropost_format_time($post_time) {

$options = get_option('microblog_setting_data');
$date_format = isset($options['mb_date_format']) ? $options['mb_date_format'] : '';
if ($date_format == 'date_format_notime'){
Expand All @@ -50,7 +51,7 @@ function micropost_format_time($post_time) {
}

function post_fuzzy_time($post_time) {
$time_diff = time() - $post_time;
$time_diff = current_time('timestamp') - $post_time;
if ($time_diff < 60) {
return '刚刚';
} elseif ($time_diff < 3600) {
Expand All @@ -69,12 +70,6 @@ function post_fuzzy_time($post_time) {
}
}







function micropost_excerpt_more($more) {
return ' ...';
}
Expand Down

0 comments on commit b5d7424

Please sign in to comment.