support sidebar widget

This commit is contained in:
spirit 2019-11-15 23:17:20 +08:00
parent ae4d65abd5
commit de636d1d08
6 changed files with 96 additions and 7 deletions

View File

@ -38,6 +38,15 @@
</div>
</div><!-- .site-info -->
</footer><!-- #colophon -->
<aside id="secondary" class="widget-area" role="complementary" style="left: -400px;">
<button class="show_hide">
<i class="fa fa-magic" aria-hidden="true"></i>
</button>
<div class="heading">小工具</div>
<div class="sakura_widget">
<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('sakura_widget')) : endif; ?>
</div>
</aside>
<div class="openNav no-select">
<div class="iconflat no-select">
<div class="icon"></div>

View File

@ -645,19 +645,19 @@ function wpjam_custom_upload_dir( $uploads ) {
* 删除自带小工具
*/
function unregister_default_widgets() {
unregister_widget("WP_Widget_Pages");
//unregister_widget("WP_Widget_Pages");
unregister_widget("WP_Widget_Calendar");
unregister_widget("WP_Widget_Archives");
//unregister_widget("WP_Widget_Archives");
unregister_widget("WP_Widget_Links");
unregister_widget("WP_Widget_Meta");
unregister_widget("WP_Widget_Search");
//unregister_widget("WP_Widget_Search");
unregister_widget("WP_Widget_Text");
unregister_widget("WP_Widget_Categories");
unregister_widget("WP_Widget_Recent_Posts");
//unregister_widget("WP_Widget_Categories");
//unregister_widget("WP_Widget_Recent_Posts");
unregister_widget("WP_Widget_Recent_Comments");
unregister_widget("WP_Widget_RSS");
unregister_widget("WP_Widget_Tag_Cloud");
unregister_widget("WP_Nav_Menu_Widget");
//unregister_widget("WP_Nav_Menu_Widget");
}
add_action("widgets_init", "unregister_default_widgets", 11);
@ -1642,4 +1642,17 @@ function sakura_comment_notify($comment_id){
}
add_action('comment_post', 'sakura_comment_notify');
//侧栏小工具
if (akina_option('sakura_widget')) {
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => '侧栏',
'id' => 'sakura_widget',
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="title"><h2>',
'after_title' => '</h2></div>'
));
}
}
//code end

View File

@ -976,6 +976,17 @@ function mail_me() {
window.open(mail);
}
function activate_widget(){
if (document.body.clientWidth > 860) {
$('.show_hide').on('click', function() {
$("#secondary").toggleClass("active")
});
}else{
$("#secondary").remove();
}
}
activate_widget();
mashiro_global.ini.normalize();
loadCSS(mashiro_option.jsdelivr_css_src);
loadCSS(mashiro_option.entry_content_theme_src);

View File

@ -954,6 +954,13 @@ function optionsframework_options() {
'id' => 'nprogress_on',
'std' => '0',
'type' => 'checkbox');
$options[] = array(
'name' => __('Enable sidebar widget', 'sakura'),/*支持侧栏小部件*/
'desc' => __('Default off, check on', 'sakura'),/*默认不开启,勾选开启*/
'id' => 'sakura_widget',
'std' => '0',
'type' => 'checkbox');
$options[] = array(
'name' => __('Enable Announcement', 'sakura'),

View File

@ -7,7 +7,8 @@
* @package Akina
*/
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
//disable get_sidebar()
if ( is_active_sidebar( 'sakura_widget' ) ) {
return;
}
?>

View File

@ -8500,3 +8500,51 @@ h1[id*=toc-head]::before,h2[id*=toc-head]::before,h3[id*=toc-head]::before,h4[id
visibility:hidden
}
.widget-area {
position: fixed;
top: 88%;
bottom: 10%;
left: -400px;
z-index: 3;
width: 400px;
webkit-transition: .3s;
transition: all .3s;
background-color: rgba(255,255,255,0.8);
box-shadow: 0 1px 20px -8px rgba(0,0,0,.5);
}
.widget-area.active{
top: 100px;
bottom: 80px;
left: -1px !important;
}
.widget-area .sakura_widget{
padding: 16px;
height: calc(100% - 30px);
overflow-y: auto;
}
.widget-area .heading{
color: #555;
font-size: 20px;
font-weight: 900;
text-align: center;
height: 30px;
background-color: #f5f5f5;
border-color: #ddd;
}
.widget-area .show_hide{
position: absolute;
right: -42px;
height: 30px;
background: #f5f5f5;
border-color: #ddd;
outline:none;
box-shadow: none;
border-left-width: 0;
}
.widget-area .show_hide .fa{
font-size: 20px;
}