前言
筛选 Bricks 存储在 Database::$page_data[‘current_page_type’] 中的当前页面类型。该值被 Bricks 用于确定动态数据和其它逻辑的上下文。
用法
将代码加入子主题的 functions.php:
add_filter( 'bricks/builder/current_page_type', function( $page_type ) {
// Example: Treat a custom endpoint as an archive
if ( get_query_var( 'my_custom_archive' ) ) {
return 'archive';
}
return $page_type;
} );
参数
$page_type(string):检测到的页面类型(例如 post、archive、search、author、404、term、user)。
示例代码
筛选返回值
add_filter( 'bricks/builder/current_page_type', function( $page_type ) {
// Example: Treat a custom endpoint as an archive
if ( get_query_var( 'my_custom_archive' ) ) {
return 'archive';
}
return $page_type;
} );
根据条件短路返回原值
根据条件跳过或修改返回值:
add_filter( 'bricks/builder/current_page_type', function( $value, $page_type ) {
if ( is_admin() ) { return $value; }
// TODO: custom logic here
return $value;
} );
补充说明
更多细节可参考 官方文档。