如果您想强制网站仅显示在特定日期之后发布的浏览次数最多的文章。将此代码添加到子主题的文件中,或通过允许添加自定义函数的插件(例如代码片段插件)添加。避免将自定义代码直接添加到父主题的文件中,因为当您更新主题时,这将被完全擦除。functions.php
代码: 全选
/**
* Display Most Viewed Posts published after a certain date
*/
add_filter( 'TieLabs/Query/args', 'custom_block_query_args' );
function custom_block_query_args( $args ){
if( ! empty( $args['meta_key'] ) && $args['meta_key'] == apply_filters( 'TieLabs/views_meta_field', 'tie_views' ) ){
$args['date_query'] = array(
'after' => array(
'year' => '2015',
'month' => '01',
'day' => '25',
)
);
}
return $args;
}
代码: 全选
/**
* Display Most Viewed Posts published in the past month
*/
add_filter( 'TieLabs/Query/args', 'custom_block_query_args_2' );
function custom_block_query_args_2( $args ){
if( ! empty( $args['meta_key'] ) && $args['meta_key'] == apply_filters( 'TieLabs/views_meta_field', 'tie_views' ) ){
$args['date_query'] = array(
array(
'column' => 'post_date_gmt',
'after' => '1 month ago',
),
);
}
return $args;
}