代码部署
首先:打开/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(
- 'name' => '分类 ID 对照',
- 'desc' => '<ul>'.$cats_id.'</ul>',
- 'id' => 'catid',
- 'class' => 'remind-catid hidden',
- 'type' => 'info'
- );
- $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文件,在适当位置添加代码:
这段代码是该功能的主体代码。
最后:打开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;
- }
完成上面的操作后,在【主题选项】中找到该功能并启用,然后根据自己的情况设置相关的参数即可。
其他说明
1、参数说明
- 超过几天提醒:比如超过 1 年的文章显示提醒信息就输入365,要使文章一发布就显示提醒信息就输入0;
- 提醒内容:可输入任意文字,不仅限于提醒类文字,但只能是纯文本文字;
- 提醒位置:默认是文章底部,勾选时为文章顶部(文章标题下面);
- 提醒分类 ID:输入想要显示提醒信息的分类 ID 即可,多个分类用英文逗号","隔开。
2、其他说明
使用相同主题的童鞋,直接按本文提供的操作步骤添加代码即可。使用其他主题的童鞋,可以参考本文的思路自行修改相关代码,也可以参考下面的代码:
- 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);
- if ($diff_time > 365 ) {
- // 提醒位置:文章顶部
- // $content = '<div class="remind_content">提醒内容</div>'. $content;
- // 提醒位置:文章底部
- $content = $content.'<div class="remind_content">提醒内容</div>';
- }
- return $content;
- }
- add_filter('the_content', 'remind_content');
代码中需要修改的内容:
365
:超过的天数;提醒内容
:修改为你想要设定的文字;提醒位置
:默认显示在文章底部,若要让提醒信息显示在文章顶部,就恢复上面那条注释并注释下面那条代码。
将修改后的代码保存到主题目录下的functions.php文件中,然后再复制上面的CSS代码到主题目录下的style.css文件中即可。
- 我的微信
- 微信扫一扫
-
- 我的微博
- 微博扫一扫
-
评论