Files
wordpress-kratos-yang/pages/page-mourning.php
T

62 lines
2.0 KiB
PHP
Raw Normal View History

<?php
/**
* 哀悼说明页的模板
*
* 由 inc/theme-mourning-page.php 的 yang_mourning_page_route() 直接 include,
* 不经过 WordPress 的模板层级。
*
* 关键点:这一页**必须是彩色的**。全站在纪念日会挂
* `html{filter:grayscale(100%)}`(wp_head 优先级 1),
* 本模板在 wp_head 优先级 2 里把它反转回来。
* 只反转 html 的 filter 不够 —— 见下方注释。
*
* @author Yongquan Yang <yangyq.net>
* @license MIT License
*/
if (!defined('ABSPATH')) {
exit;
}
/**
* 把灰度反转掉
*
* 为什么写两遍:
* - `html{filter:none}` 取消外面的灰度;
* - 但某些浏览器在 filter 从有到无的瞬间会留下合成层缓存,导致首屏仍是灰的,
* 所以补一条 `filter:grayscale(0%)` 显式声明,比 none 更稳。
*
* 权限用 `!important`:主题的灰度样式在 wp_head 优先级 1 输出,
* 本段在优先级 2,同优先级下后写的赢,加 !important 是防其它插件插入的覆盖。
*/
function yang_mourning_page_ungrayscale()
{
echo '<style id="yang-mourning-page-color">'
. "\nhtml{filter:none !important;-webkit-filter:none !important;}"
. "\nhtml{filter:grayscale(0%) !important;-webkit-filter:grayscale(0%) !important;}"
. "\nhtml body{-webkit-transform:none !important;}"
. "\n</style>\n";
}
add_action('wp_head', 'yang_mourning_page_ungrayscale', 2);
/**
* 输出本页样式
*/
function yang_mourning_page_print_css()
{
echo '<style id="yang-mourning-page">' . yang_mourning_page_css() . "</style>\n";
}
add_action('wp_head', 'yang_mourning_page_print_css', 3);
get_header();
?>
<div class="k-main <?php echo kratos_option('top_select', 'banner'); ?>" style="background:<?php echo kratos_option('g_background', '#f5f5f5'); ?>">
<div class="container">
<div class="row">
<div class="col-12">
<?php echo yang_mourning_page_content(); ?>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>