您好,尝试使用下面的代码开始工作,但目前还看不到。 如果页面模板是 第47页.php 展示 <h1>Something</h1>
别的 <h1>This will show on any other page</h1>
.
<?php if ( is_page_template( 'page-47.php' ) ): ?>
<h1>Something</h1>
<?php else: ?>
<h1>This will show on any other page</h1>
<?php endif ?>
谢谢
is_page_template()
只会告诉你页面是否使用 风俗 页面模板。 意思是通过添加创建的模板 Template Name:
注释文件并从模板下拉列表中选择它,如此处所述。 该功能通过检查为其选择模板的帖子元来工作。
如果您使用此处描述的方法使用 slug 或 ID 创建了页面模板,您似乎拥有,则正在使用的模板未存储在元数据中,因此不会被 is_page_template()
功能。
如果你想知道当前正在使用的模板的文件名,不管它是否是自定义模板,你可以使用全局 $template
多变的:
global $template;
if ( basename( $template ) === 'page-47.php' ) {
}
感谢雅各布皮蒂! 这也解决了我的问题。
add_filter( 'woocommerce_currency_symbol', 'change_currency_symbol', 10, 2 );
function change_currency_symbol( $symbols, $currency ) {
global $template;
if ( basename( $template ) === 'archive-chiptuning.php' && ( 'EUR' === $currency )) {
return '';
}
return $symbols;
}
