这些实际上是后状态;不是别名。。你可以通过display_post_states
过滤器,就像这样,我们检查post ID($post->ID
) 是123
如果是,我们分配XYZ Page
该帖子的状态(可以是页面、自定义帖子类型等):
add_filter( \'display_post_states\', \'my_post_states\', 10, 2 );
function my_post_states( $post_states, $post ) {
if ( 123 === $post->ID ) {
$post_states[\'xyz_page\'] = \'XYZ Page\';
}
return $post_states;
}
作为参考,这是WordPress用于“首页”和“贴子页”的条件声明:
if ( \'page\' === get_option( \'show_on_front\' ) ) {
if ( intval( get_option( \'page_on_front\' ) ) === $post->ID ) {
$post_states[\'page_on_front\'] = __( \'Front Page\' );
}
if ( intval( get_option( \'page_for_posts\' ) ) === $post->ID ) {
$post_states[\'page_for_posts\'] = __( \'Posts Page\' );
}
}