Open/closed function

时间:2018-02-05 作者:Jordan Kellett

我已经为我正在开发的网站创建了一个打开/关闭功能,我正在尝试添加最后的触摸,但我被卡住了。

如何添加跨距显示它显示了一个绿点和一个红色的圆点,前者为打开,后者为css脉冲动画,后者为关闭。我添加了一个示例。https://www.clicky.co.uk/

Shortcode:

[linestatus] [linestatus open_time="08:00:00" closed_time="17:00:00" open_text="open" closed_text="closed"]

PHP Function

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 ) ); 

    if ( time() >= strtotime( $open_time ) && time() <= strtotime( $closed_time ) ) { 
        $output = $open_text; 
    } else { 
        $output = $closed_text; 
    } 
    return $output; 
}

1 个回复
最合适的回答,由SO网友:David Sword 整理而成

我从

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。我用一个带有页脚钩子的匿名函数将其打包,这样它就可以放在屏幕的底部,而不是放在短代码所在的任何地方。

结束

相关推荐

WordPress小工具和Customize.php在Ubuntu16.04 VPS中不起作用

我在Ubuntu16有一个WordPress网站。04 VPS。问题是,我无法编辑我的小部件区域customize.php 在我的WordPress网站中不起作用。我想这是因为谷歌没有验证我的服务器?我们对此不太确定。我试图触发错误,并花了我的时间去做,因为这个错误在我的日志中有点疯狂。下面是error.log: [Tue Jan 30 11:39:21.584827 2018] [:error] [pid 3369] [client 52.221.193.115:53650] PHP Fatal