Wordpress,条件声明,显示每月一周的表格

时间:2015-08-03 11:14:42

标签: wordpress

我有wordpress 4.2网站。我有一个邮件表格构建与“联系表格7”。我把它放在一个单独的页面上,并附上下一个声明:

select (sum(case when status = 'sold' then pieces else 0 end) -
        sum(case when status = 'returned' then - pieces else 0 end)
       ) / (1 + datediff(max(date), min(date))
from . . .;

我想把它放在其他条件声明中,以便每月只显示一周。 正如我所读到的,Wordpress没有像Rails或Django这样的模板服务器语言。 我怎样才能每月只显示一些内容。

1 个答案:

答案 0 :(得分:0)

简码:

您可以创建[visible]短代码并将其包装在您的内容中:

[visible from="1" to="7"]
    [contact-form-7 id="2" title="Counter"]
[/visible]

其中fromto月的值(1 - 31)。

插件:

这是一个未经测试的演示插件:

<?php 
/* Plugin Name: Visible - Shortcode */

add_shortcode( 'visible', function( $atts = [], $content = '' )
{
    $a = shortcode_atts(
        [
            'from' => '1',
            'to'   => '7',
        ], 
        $atts, 
        'visible_shortcode' 
    );

    $j = current_time( 'j' );

    return (int) $a['from'] <= $j && $j <= (int) $a['to']
        ? do_shortcode( $content ) 
        : __( 'Hidden!' );

} );

希望您可以根据自己的需要进行调整。