我需要在存档中输出自定义帖子类型的名称。php和single。php。
我会用这样的东西:
if ( \'staff\' == get_post_type() ) {
$post_type = \'staff\';
}
echo \'<div class="\'.$post_type.\'">Content</div>\';
这将为我提供<div class="staff">
但是,我似乎也可以访问名为$post_type
只需将其归档即可。php或单个。php即使没有声明global
, 例如,这将存档与上述相同的结果:
<div class="<?php echo $post_type; ?>">
Codex表示全局变量$post_type
用于Wordpress管理区域。我的问题是:
为什么$post_type
在不首先在全球范围内声明的情况下工作$post_type 在主题模板中使用如上所示的全局var