我如何获取single.php pods页面的模板文件?

时间:2018-11-13 06:09:28

标签: php wordpress custom-wordpress-pages

我当前正在使用名为single-product.php的模板文件,并想检查header.php中的页面模板。我尝试使用get_page_template_slug($post->ID),但返回空值。我也尝试过is_page_template('single-product.php');,但也不会返回任何内容。

这是我的标题。您会注意到,我正在尝试通过s_page_template('single-product.php') ny来获取模板文件,在顶部将其设置为$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'>";
    }
    ?>

0 个答案:

没有答案