2016-01-06 64 views
0

我正在創建自定義主題,但遇到了一些問題。爲了您的信息,我的文件,如下圖所示:wordpress未加載在the_content()或footer.php

themes/ 
    aq-aquatics/ 
     css/ 
     img/ 
     js/ 
     footer.php 
     functions.php 
     header.php 
     index.php 
     page-homepage.php 
     page-wide.php 
     style.css 
    index.php 

這是我的header.php

<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<!-- Latest compiled and minified CSS --> 
<link rel="stylesheet" href="<?= get_template_directory_uri(); ?>/css/bootstrap.min.css"> 
<link href='https://fonts.googleapis.com/css?family=Asap:400,700' rel='stylesheet' type='text/css'> 
<link href="http://fonts.googleapis.com/css?family=Arvo:400,700,400italic,700italic" rel="stylesheet" type="text/css"> 
<meta name="viewport" content="width=device-width, initial-scale=1" /> 
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> 
<meta name="author" content="Matthew Smart"> 
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> 
<!--[if lt IE 9]> 
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> 
<![endif]--> 
<title><?php wp_title(); ?></title> 

<?php wp_head(); ?> 

</head> 
<body> 
<div class="wrap"> 
<header> 
    <div class="header-top text-right"> 
     <div class="container"> 
      <span style="margin-right:40px;">Tel: 01922 418050</span><span>Email: [email protected]</span> 
     </div> 
    </div> 
    <div class="container"> 
     <div class="header-content" style="min-height:86px;"> 
      <div class="row"> 
       <div class="col-sm-1" style="position:absolute;top:11px;z-index:1000;"> 
        <img src="<?= get_template_directory_uri(); ?>/img/logo.png" width="108" height="100" alt="a&d logo"/> 
       </div> 
       <div class="col-sm-offset-1 col-sm-10 text-right" style="margin-left:132px;"> 
        <nav class="navbar"> 
         <div class="container"> 
          <div> 
           <ul class="nav navbar-nav" style="width:inherit; border-bottom:none !important;margin-top:31px;"> 
            <li class="active"><a href="#">Home</a></li> 
            <li class="dropdown"> 
             <a class="dropdown-toggle" data-toggle="dropdown" href="#">At A & D 
              <span class="caret"></span></a> 
             <ul class="dropdown-menu"> 
              <li><a href="#">Page 1-1</a></li> 
              <li><a href="#">Page 1-2</a></li> 
              <li><a href="#">Page 1-3</a></li> 
             </ul> 
            </li> 
            <li class="dropdown"> 
             <a class="dropdown-toggle" data-toggle="dropdown" href="#">Aquatics 
              <span class="caret"></span></a> 
             <ul class="dropdown-menu"> 
              <li><a href="#">Tropical</a></li> 
              <li><a href="#">Pond</a></li> 
              <li><a href="#">Marine</a></li> 
              <li><a href="#">Cold water</a></li> 
              <li><a href="#">Aquatics Sundries</a></li> 
             </ul> 
            </li> 
            <li><a href="#">Valencia Wharf Coffee Shop</a></li> 
            <li><a href="#">Opening Times</a></li> 
            <li><a href="#">Contact Us</a></li> 
           </ul> 
          </div> 
         </div> 
        </nav> 
       </div> 
      </div> 
     </div> 
    </div> 
    <div class="purple-line" style="margin-bottom:25px;"></div> 
</header> 

這是我page.wide.php

<?php 
/* 
Template Name: Wide Page 
*/ 
get_header(); 

?> 


<?php 
if (have_posts()) { 
    while (have_posts()) { 
     // 
     // Post Content here 
     the_content(); 
     // 
    } // end while 
} // end if 
?> 


<?php get_footer(); ?> 

這是我頁腳.php

<footer> 
<div class="container"> 
    <div class="col-sm-6"> 
     A&D AQUATIC & GARDEN CENTRE | WEBSITE DESIGN BY <span>MATTHEW SMART</span> 
    </div> 
    <div class="col-sm-6 text-right"> 
     <ul> 
      <li>TERMS AND CONDITIONS</li> 
      <li>PRIVACY POLICY</li> 
      <li>COOKES</li> 
     </ul> 
    </div> 
</div> 

</footer> 


</div><!-- End WRAP --> 
<?php wp_footer(); ?> 
</body> 
</html> 

現在頁面ia m試圖測試使用寬模板。我在編輯器中添加了一些虛擬文本並單擊發布。

現在,當我嘗試訪問該頁面時,我可以看到的第一件事是標題的一部分。瀏覽器然後需要5秒鐘,並加載我的header.php文件中的導航。

它似乎只是忽略了頁面模板和事後的所有內容。所以the_content()什麼也不拉,頁腳不顯示。

我一直在比較這些文件與我創建的其他主題,似乎無法找到原因。

有誰知道爲什麼會發生這種情況?

謝謝

回答

1

您的循環缺少the_post()。

<?php 
if (have_posts()) { 
    while (have_posts()) { 
     the_post(); 
     // 
     // Post Content here 
     the_content(); 
     // 
    } // end while 
} // end if 
?> 

https://codex.wordpress.org/Function_Reference/the_post

這是必要的,讓WordPress的知道你是內環路,並檢索請求後的數據。頁腳不加載,因爲頁面在調用the_content()時出錯,並且無法在循環外處理此函數。

根據WordPress documentation the_content「必須在The_Loop內」。