给长期无更新旧文章增加自定义提示内容
首先:打开【/inc/options/begin-options.php】文件,在适当位置添加代码
$options[] = array( 'name' => '文章提醒信息', 'desc' => '显示', 'id' => 'remind_content', 'class' => 'be_ico', 'std' => '0', 'type' => 'checkbox' ); $options[] = array( 'name' => '', 'desc' => '超过几天提醒', 'id' => 'remind_over_time', 'class' => 'be_ico hidden', 'std' => '365', 'type' => 'text' ); $options[] = array( 'name' => '', 'desc' => '提醒内容', 'id' => 'remind_message', 'class' => 'be_ico hidden', 'std' => '如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!', 'type' => 'text' ); $options[] = array( 'name' => '', 'desc' => '提醒位置:文章顶部,默认提醒位置为文章底部', 'id' => 'remind_position', 'class' => 'be_ico hidden', 'std' => '', 'type' => 'checkbox' ); $options[] = array( 'name' => '', 'desc' => '输入提醒的分类 ID,多个分类用英文半角逗号","隔开', 'id' => 'remind_id', 'class' => 'hidden', 'std' => '', 'type' => 'text' ); $options[] = array( 'id' => 'clear' );
然后:打开【/inc/options/includes/themes-options.php】文件,在适当位置添加代码
jQuery('#remind_content').click(function() {
jQuery('#section-remind_over_time, #section-remind_message, #section-remind_position, #section-remind_id, .remind-catid').fadeToggle(400);
});
if (jQuery('#remind_content:checked').val() !== undefined) {
jQuery('#section-remind_over_time, #section-remind_message, #section-remind_position, #section-remind_id, .remind-catid').show();
}
这段代码主要就是给上面的功能添加展开/闭合功能,当不启用该功能时,该功能下的选项将被隐藏。
接着:打开【/inc/inc.php】文件,在适当位置添加代码
// 文章提醒信息
if (zm_get_option('remind_content')) {
function remind_content($content) {
$modified_time = get_the_modified_time('U');
$current_time = current_time('timestamp');
$diff_time = ($current_time - $modified_time) / (60 * 60 * 24);
$remind_over_time = zm_get_option('remind_over_time');
if ($diff_time > $remind_over_time && in_category(explode(',',zm_get_option('remind_id'))) ) {
if (zm_get_option('remind_position')) {
$content = '<div class="remind_content">'.zm_get_option('remind_message').'</div>'. $content;
} else {
$content = $content.'<div class="remind_content">'.zm_get_option('remind_message').'</div>';
}
}
return $content;
}
add_filter('the_content', 'remind_content');
}
最后:打开【style.css】文件,在适当位置添加代码
/* 文章提醒信息 */
.remind_content {
color: #db7c22;
background: #fffcef;
border: 1px solid #ffbb76;
border-radius: 2px;
overflow: hidden;
margin: 20px 0;
padding: 10px 15px;
font-size: 14px;
}
完成上面的操作后,在【主题选项】中找到该功能并启用,然后根据自己的情况设置相关的参数即可。
效果图:
以上就是爱游博客的一些改造,如有好的建议或是那里有问题,请在下方留言。
版权申明:

请先 !