我从
https://codepen.io/vram1980/pen/Kyaie
以上所有信用。将其与功能结合起来,可以执行以下操作:
add_shortcode( \'linestatus\', \'line_status_handler\' );
function line_status_handler( $atts ) {
extract( shortcode_atts( array(
\'open_time\' => \'09:00:00\',
\'closed_time\' => \'17:00:00\',
\'open_text\' => \'our lines are open\',
\'closed_text\' => \'our lines are closed\',
), $atts ) );
$opened = (time() >= strtotime( $open_time )) ? true : false;
$notClosed = (time() <= strtotime( $closed_time )) ? true : false;;
$status = ($opened && $notClosed) ? \'open\' : \'closed\';
add_action(\'wp_footer\',function(){
?>
<style>
.ring-container {
position: relative;
height: 50px;
}
.circle {
width: 15px;
height: 15px;
background-color: #62bd19;
border-radius: 50%;
position: absolute;
top: 23px;
left: 23px;
}
.ringring {
border: 3px solid #62bd19;
-webkit-border-radius: 30px;
height: 25px;
width: 25px;
position: absolute;
left: 15px;
top: 15px;
-webkit-animation: pulsate 1s ease-out;
-webkit-animation-iteration-count: infinite;
opacity: 0.0
}
.ring-container--closed .circle {
background-color: red;
}
.ring-container--closed .ringring {
border: 3px solid #ff7777;
}
@-webkit-keyframes pulsate {
0% {-webkit-transform: scale(0.1, 0.1); opacity: 0.0;}
50% {opacity: 1.0;}
100% {-webkit-transform: scale(1.2, 1.2); opacity: 0.0;}
}
</style>
<?php
});
return \'
<div class="ring-container ring-container--\'.$status.\'">
<div class="ringring"></div>
<div class="circle"></div>
</div>\';
}
您可能希望在主题的样式表中加入CSS。我用一个带有页脚钩子的匿名函数将其打包,这样它就可以放在屏幕的底部,而不是放在短代码所在的任何地方。