php - 如何获取 single.php pod 页面的模板文件?
问题描述
我目前正在使用一个名为的模板文件single-product.php
,并希望在header.php
. 我试过使用get_page_template_slug($post->ID)
,但它返回空。我也尝试过is_page_template('single-product.php');
,但也没有任何回报。
这是我的标题。您会注意到我正在尝试通过将模板文件s_page_template('single-product.php')
设置为$isProductPodTemplate
顶部的值并在底部的 if 语句中使用它来获取模板文件:
<?php
$page = get_the_title($post->ID);
$frontpageId = get_option('page_on_front');
$isStandardTemplate = is_page_template('standard.php');
$isContactTemplate = is_page_template('contact.php');
$isProductPodTemplate = is_page_template('single-product.php');
?>
<!DOCTYPE html>
<html id="mainHTML" lang="en">
<head>
<title>Architectural Iron Works</title>
<meta name="description" content="Architectural Iron Works">
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- <link rel=icon type="img/ico" href=/favicon.ico> -->
<link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_directory_uri(); ?>/main.bundle.css" />
<link href="https://fonts.googleapis.com/css?family=Poiret+One" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<?php wp_head(); ?>
<script type="text/javascript">
document.getElementById("mainHTML").style.display = "none";
</script>
</head>
<body>
<!-- Header -->
<?php
if ($post->ID == $frontpageId)
{
get_template_part('/includes/_home-header');
echo "<div class='main-content'>";
}
else if (is_404() ||
$isContactTemplate ||
$isStandardTemplate)
{
get_template_part('/includes/_no-banner-header');
echo "<div class='main-content no-banner'>";
}
else if ($isProductPodTemplate)
{
// do something
}
else
{
get_template_part('/includes/_default-header');
echo "<div class='main-content'>";
}
?>
解决方案
推荐阅读
- reactjs - 如何从 fullcalendar 的 eventClick 中访问 JSX 函数
- excel - 使用MATLAB通过ActiveX协议将String值写入Excel电子表格..发现问题
- reactjs - 单击按钮时如何修复 onSubmit 函数不显示状态?
- c# - 如何在c#中将数字转换为十进制格式的值?
- java - 如何使用 Jsoup 读取 h3 和之后的文本元素?
- python - 查找作为列表存在的列元素的数据框索引的最快方法
- keras - 当我想计算灵敏度和特异性时,Keras 中的错误
- unity3d - 3d 物体位置跳跃运动
- excel - 无法使用年龄和性别正确输入 AVERAGEIF
- python - 存在于位置时未找到 Raspberry Pi 文件