Skip to content

Commit

Permalink
✨ 增加众多小工具模块区域
Browse files Browse the repository at this point in the history
  • Loading branch information
Licoy committed Oct 25, 2022
1 parent 3b38dc1 commit 6ba7c5b
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 125 deletions.
7 changes: 7 additions & 0 deletions inc/fun/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ function pk_hide_sidebar_out($hide = '', $show = '', $post_id = null, $echo = tr
echo $out;
}

//侧边栏检测数据
function pk_sidebar_check_has($name){
if(!dynamic_sidebar($name)){
dynamic_sidebar('sidebar_not');
}
}

//获取链接对象,用于书籍推荐及其他页面使用
function pk_get_wp_links($link_cats = '')
{
Expand Down
3 changes: 0 additions & 3 deletions inc/fun/opt.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,6 @@ function pk_post_menu_id($content)
function pk_compatible()
{
wp_scripts()->remove("Editormd_Front");
if (!is_admin()) {
wp_deregister_script('jquery');
}
}

add_action('wp_enqueue_scripts', 'pk_compatible', 999);
Expand Down
104 changes: 33 additions & 71 deletions inc/fun/sidebar.php
Original file line number Diff line number Diff line change
@@ -1,72 +1,34 @@
<?php


register_sidebar(array(
'name' => __( '正文内容侧边栏' ),
'id' => 'sidebar_single',
'description' => __( '文章正文内容侧边栏' ),
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );

register_sidebar(array(
'name' => __( '首页侧边栏' ),
'id' => 'sidebar_home',
'description' => __( '首页侧边栏' ),
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );

register_sidebar(array(
'name' => __( '搜索页侧边栏' ),
'id' => 'sidebar_search',
'description' => __( '搜索页侧边栏' ),
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );

register_sidebar(array(
'name' => __( '分类/标签页侧边栏' ),
'id' => 'sidebar_cat',
'description' => __( '分类/标签页侧边栏' ),
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );

register_sidebar(array(
'name' => __( '单页面侧边栏' ),
'id' => 'sidebar_page',
'description' => __( '单页面侧边栏' ),
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );

register_sidebar(array(
'name' => __( '其他页面侧边栏' ),
'id' => 'sidebar_other',
'description' => __( '包括作者/404等其他页面' ),
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );

register_sidebar(array(
'name' => __( '通用侧边栏' ),
'id' => 'sidebar_not',
'description' => __( '若指定页面未配置任何栏目,则显示此栏目下的数据' ),
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );
add_action('widgets_init', 'pk_widgets_init');
function pk_widgets_init()
{
pk_common_sidebar_register('sidebar_single', '正文内容 - 侧边栏', '文章正文内容侧边栏');
pk_common_sidebar_register('sidebar_home', '首页 - 侧边栏', '首页侧边栏');
pk_common_sidebar_register('sidebar_search', '搜索页 - 侧边栏', '搜索页侧边栏');
pk_common_sidebar_register('sidebar_cat', '分类/标签页 - 侧边栏', '分类/标签页侧边栏');
pk_common_sidebar_register('sidebar_page', '单页面 - 侧边栏', '单页面侧边栏');
pk_common_sidebar_register('sidebar_other', '其他页面 - 侧边栏', '包括作者/404等其他页面');
pk_common_sidebar_register('sidebar_not', '通用 - 侧边栏', '若指定页面未配置任何栏目,则显示此栏目下的数据');
pk_common_sidebar_register('post_content_author_top', '正文 - 作者上方栏目', '显示在正文作者栏上方的栏目');
pk_common_sidebar_register('post_content_author_bottom', '正文 - 作者下方栏目', '显示在正文作者栏下方的栏目');
pk_common_sidebar_register('index_bottom', '首页 - 底部栏目', '显示在首页内容最底部(友情链接上方的通栏项)');
pk_common_sidebar_register('index_cms_layout_top', 'CMS布局 - 分类栏上方栏目', 'CMS布局下显示在分类栏之上的栏目');
pk_common_sidebar_register('index_cms_layout_bottom', 'CMS布局 - 分类栏下方栏目', 'CMS布局下显示在分类栏之下的栏目');
pk_common_sidebar_register('post_content_comment_top', '正文 - 评论上方栏目', '显示在正文评论上方的栏目');
pk_common_sidebar_register('post_content_comment_bottom', '正文 - 评论下方栏目', '显示在正文评论下方的栏目');
pk_common_sidebar_register('page_content_comment_top', '页面 - 评论上方栏目', '显示在页面评论上方的栏目');
pk_common_sidebar_register('page_content_comment_bottom', '页面 - 评论下方栏目', '显示在页面评论下方的栏目');
}

function pk_common_sidebar_register($id, $name, $description = '')
{
register_sidebar(array(
'name' => __($name, PUOCK),
'id' => $id,
'description' => __($description, PUOCK),
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
));
}
2 changes: 1 addition & 1 deletion inc/fun/widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function get_common_widget_header($instance){
$show_title = !array_key_exists('hide_title',$instance) || !$this->is_checked($instance['hide_title'])
?>

<div class="p-block <?php echo $instance['classes'] ?>">
<div class="pk-widget p-block <?php echo $instance['classes'] ?>">
<?php if($show_title): ?>
<div>
<span class="t-lg border-bottom border-primary
Expand Down
22 changes: 11 additions & 11 deletions inc/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ function deel_setup()
remove_action('wp_head', 'wp_oembed_add_host_js');
remove_filter('pre_oembed_result', 'wp_filter_pre_oembed_result', 10);

// 屏蔽 REST API
if(pk_is_checked('close_rest_api')){
add_filter('rest_enabled', '__return_false');
add_filter('rest_jsonp_enabled', '__return_false');
add_filter( 'rest_authentication_errors', function( $access ) {
return new WP_Error( 'rest_cannot_access', 'REST API已经被关闭,请打开后再进行尝试', array( 'status' => 403 ) );
});
}
// 屏蔽 REST API
if (pk_is_checked('close_rest_api')) {
add_filter('rest_enabled', '__return_false');
add_filter('rest_jsonp_enabled', '__return_false');
add_filter('rest_authentication_errors', function ($access) {
return new WP_Error('rest_cannot_access', 'REST API已经被关闭,请打开后再进行尝试', array('status' => 403));
});
}

// 移除头部 wp-json 标签和 HTTP header 中的 link
// 移除头部 wp-json 标签和 HTTP header 中的 link
remove_action('wp_head', 'rest_output_link_wp_head', 10);
remove_action('template_redirect', 'rest_output_link_header', 11);

//清除wp_footer带入的embed.min.js
//清除wp_footer带入的embed.min.js
function git_deregister_embed_script()
{
wp_deregister_script('wp-embed');
}

add_action('wp_footer', 'git_deregister_embed_script');

//禁止 s.w.org
//禁止 s.w.org
function git_remove_dns_prefetch($hints, $relation_type)
{
if ('dns-prefetch' === $relation_type) {
Expand Down
25 changes: 14 additions & 11 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
<?php get_header() ?>

<?php if(pk_get_option('index_mode')!='company'): ?>
<?php if (pk_get_option('index_mode') != 'company'): ?>

<div id="content" class="mt15 container">
<?php get_template_part('ad/global','top') ?>
<?php get_template_part('ad/global', 'top') ?>
<div class="row row-cols-1">
<div class="col-lg-<?php pk_hide_sidebar_out('12','8') ?> col-md-12 <?php pk_open_box_animated('animated fadeInLeft') ?> ">
<?php if(isset($paged) && $paged<=1): ?>
<div class="col-lg-<?php pk_hide_sidebar_out('12', '8') ?> col-md-12 <?php pk_open_box_animated('animated fadeInLeft') ?> ">
<?php if (isset($paged) && $paged <= 1): ?>
<div class="<?php pk_open_box_animated('animated fadeInLeft') ?>">
<?php get_template_part('templates/module','banners') ?>
<?php get_template_part('templates/module', 'banners') ?>
</div>
<?php endif; ?>
<div class="<?php pk_open_box_animated('animated fadeInLeft') ?>
<?php echo pk_post_style_list() ? '':'pr-0 pl-0' ?>">
<?php echo pk_post_style_list() ? '' : 'pr-0 pl-0' ?>">
<div>
<?php get_template_part('templates/module','posts') ?>
<?php get_template_part('templates/module', 'posts') ?>
</div>
</div>
</div>
<?php get_sidebar() ?>
</div>

<?php get_template_part('templates/module','cms') ?>
<?php get_template_part('templates/module', 'cms') ?>

<?php get_template_part('templates/module','links') ?>
<?php get_template_part('templates/module', 'links') ?>

<?php get_template_part('ad/global', 'bottom') ?>

<?php dynamic_sidebar('index_bottom') ?>

<?php get_template_part('ad/global','bottom') ?>
</div>

<?php else: get_template_part('templates/page','company'); endif; ?>
<?php else: get_template_part('templates/page', 'company'); endif; ?>



Expand Down
2 changes: 2 additions & 0 deletions page.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class="fa-regular fa-pen-to-square mr-1"></i><?php _e('编辑', PUOCK) ?></div>
<?php endif; ?>
</div>
</div>
<?php dynamic_sidebar('page_content_comment_top'); ?>
<?php comments_template() ?>
<?php dynamic_sidebar('page_content_comment_bottom'); ?>
</div>
<?php get_sidebar() ?>
</div>
Expand Down
47 changes: 20 additions & 27 deletions sidebar.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
<?php if(pk_hide_sidebar()==false): ?>
<div id="sidebar" class="<?php pk_open_box_animated('animated fadeInRight') ?> col-lg-4 d-none d-lg-block">
<div class="sidebar-main">
<?php

function sidebar_check_has($name){
if(!dynamic_sidebar($name)){
dynamic_sidebar('sidebar_not');
}
}
if(is_home()):
sidebar_check_has('sidebar_home');
elseif(is_single()):
sidebar_check_has('sidebar_single');
elseif(is_search()):
sidebar_check_has('sidebar_search');
elseif(is_category() || is_tag()):
sidebar_check_has('sidebar_cat');
elseif(is_page()):
sidebar_check_has('sidebar_page');
else:
sidebar_check_has('sidebar_other');
endif;

?>
<?php if (!pk_hide_sidebar()): ?>
<div id="sidebar" class="<?php pk_open_box_animated('animated fadeInRight') ?> col-lg-4 d-none d-lg-block">
<div class="sidebar-main">
<?php
if (is_home()):
pk_sidebar_check_has('sidebar_home');
elseif (is_single()):
pk_sidebar_check_has('sidebar_single');
elseif (is_search()):
pk_sidebar_check_has('sidebar_search');
elseif (is_category() || is_tag()):
pk_sidebar_check_has('sidebar_cat');
elseif (is_page()):
pk_sidebar_check_has('sidebar_page');
else:
pk_sidebar_check_has('sidebar_other');
endif;
?>
</div>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
4 changes: 4 additions & 0 deletions single.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class="fa-regular fa-pen-to-square mr-1"></i><?php _e('编辑', PUOCK) ?></div>
</div>
<?php get_template_part('templates/post', 'actions') ?>
</div>
<?php dynamic_sidebar('post_content_author_top'); ?>
<?php if (pk_is_checked('page_copy_right')): ?>
<div class="p-block p-flex-sc">
<div class="mr-3 d-none d-md-block">
Expand Down Expand Up @@ -125,12 +126,15 @@ class="c-sub"><?php _e('此文章非本站原创文章,若需转载请联系
</div>
</div>
<?php endif; ?>
<?php dynamic_sidebar('post_content_author_bottom'); ?>
<?php get_template_part('ad/page', 'innerb') ?>
<?php if (pk_is_checked('page_b_recommend')): ?>
<?php get_template_part('templates/post', 'relevant') ?>
<?php endif; ?>
<?php get_template_part('templates/module', 'andb') ?>
<?php dynamic_sidebar('post_content_comment_top'); ?>
<?php comments_template() ?>
<?php dynamic_sidebar('post_content_comment_bottom'); ?>
</div>
<?php get_sidebar() ?>
</div>
Expand Down
4 changes: 3 additions & 1 deletion templates/module-cms.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php if (in_array(pk_get_option('index_mode', ''), array('cms', 'company'))
&& (pk_is_checked('cms_show_2box') || pk_is_checked('company_show_2box'))): ?>
<?php dynamic_sidebar('index_cms_layout_top') ?>
<div class="row row-cols-1 <?php pk_open_box_animated('animated fadeInUp') ?> " id="magazines">
<?php
$cms_mode = pk_get_option('index_mode', '') == 'cms' ? 'cms' : 'company';
Expand All @@ -9,7 +10,7 @@
if (count($cms_cats) > 0) {
$cms_cats_num = pk_get_option($cms_mode . '_show_2box_num', '6');
foreach ($cms_cats as $catId):
$cache_key = sprintf(PKC_CMS_2BOX_POSTS,$catId);
$cache_key = sprintf(PKC_CMS_2BOX_POSTS, $catId);
$posts = pk_cache_get($cache_key);
if (!$posts) {
$posts = query_posts(array(
Expand Down Expand Up @@ -71,4 +72,5 @@
}
} ?>
</div>
<?php dynamic_sidebar('index_cms_layout_bottom') ?>
<?php endif; ?>

0 comments on commit 6ba7c5b

Please sign in to comment.