首页 > 解决方案 > 如何获取 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'>";
    }
    ?>

标签: phpwordpresscustom-wordpress-pages

解决方案


推荐阅读