php get函数在wordpress中不起作用

标签 php html css mysql wordpress

在这里,我试图在 wordpress 主题中转换我的 html 和 css 模板,我有四个 php 文件 (1) index.php,(2) header.php,(3) feature.php 和 (4) footer.php .
在 index.php 文件中,我使用函数 <?php get_header(); ?>, <?php get_feature (); ?>,<?php get_footer (); ?> 获取其他三个文件.
现在开始使用函数 <?php get_header(); ?>,<?php get_footer (); ?>在 index.php 中,它显示了页眉和页 footer 分,但包含了 <?php get_feature (); ?>在页眉和页脚之间显示错误指示 <?php get_feature (); ?>行说“ fatal error :在第 2 行调用 C:\xampp\htdocs\Alvin Lemo\wordpress\wp-content\themes\alvinlimo\index.php 中的未定义函数 get_feature()”并且不显示功能部分和页 footer 分。

下面是我做的

在 index.php 中

<?php get_header (); ?>
<?php get_feature(); ?> <!--- Error Showing Line -->
<?php get_footer (); ?>

在 header.php 中

<!DOCTYPE html>
<html class="no-js" lang="en"> 
<head>    
<!--- Basic Page Needs
 ================================================== -->
<meta charset="utf-8">
<title>Alvin Lemo</title>
<meta name="description" content="">  
<meta name="author" content="">
<!-- Mobile Specific Metas
 ================================================== -->
<meta name="viewport" content="width=device-width, initial-scale=1,  maximum-scale=1">

<link href="<?php bloginfo('stylesheet_url'); ?>" rel="stylesheet" />

<link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet"> 
<link href="https://fonts.googleapis.com/css?family=Abel" rel="stylesheet"> 

<!-- Script
================================================== -->
<script src="js/modernizr.js"></script>

 <!-- Favicons
 ================================================== -->
 <link rel="shortcut icon" href="favicon.png" >   
 <?php wp_head (); ?>
</head>
<body>
<div id="myNav" class="overlay">
    <a href="javascript:void(0)" class="closebtn" onclick="closeNav()" style="margin-top:30px;">&times;</a>
    <div class="overlay-content">
        <div class="container">
            <h2 style="color:white">Please Login To Resere Your Fleet With Us</h2><br />

            <form>
                <div class="form-group">

                    <input class="form-control" id="email" style="width:50%;height:40px;color:black;border-radius:4px;font-size:18px" placeholder="Enter email"><br /><br />
                </div>
                <div class="form-group">

                    <input  class="form-control" id="pwd" style="width:50%;height:40px;color:black;border-radius:4px;font-size:18px" placeholder="Enter password"><br /><br />
                </div>
                <div class="checkbox">

                </div>
                <button type="submit" class="btn btn-default">Rserve</button>
            </form>
        </div>
    </div>
</div>

<div id="myNavv" class="overlay">
    <a href="javascript:void(0)" class="closebtn" onclick="closeNavv()" style="margin-top:30px;">&times;</a>
    <div class="overlay-content">
        <div class="container">
            <h2 style="color:white">Please Register To Reserve Your Fleet </h2><br />

            <form>
                <div class="form-group">

                    <input class="form-control" id="email" style="width:50%;height:40px;color:black;border-radius:4px;font-size:18px" placeholder="Enter FullName"><br /><br />
                </div>
                <div class="form-group">

                    <input class="form-control" id="email" style="width:50%;height:40px;color:black;border-radius:4px;font-size:18px" placeholder="Enter email"><br /><br />
                </div>
                <div class="form-group">

                    <input class="form-control" id="pwd" style="width:50%;height:40px;color:black;border-radius:4px;font-size:18px" placeholder="Enter password"><br /><br />
                </div>

                <button type="submit" class="btn btn-default">Register</button>
            </form>
        </div>
    </div>
</div>

   <!-- Header
   ================================================== -->
  <header>
      <div class="logo">
         <a class="smoothscroll" href="#hero"><!--<img alt="" src="images/logo.png">-->
      <h2>A.L.S</h2>
      </a>
  </div>
  <nav id="nav-wrap">         

     <a class="mobile-btn" href="#nav-wrap" title="Show navigation">Show Menu</a>
      <a class="mobile-btn" href="#" title="Hide navigation">Hide Menu</a>         

     <ul id="nav" class="nav">
        <li><a class="smoothscroll" href="#features">EVENT TRANSPORTATION</a></li>
         <li><a class="smoothscroll" href="#pricing">Services</a></li>
        <li><a class="smoothscroll" href="#screenshots">OUR FLEET</a></li>
        <li><a class="smoothscroll" href="#testimonials">Testimonials</a></li>
        <li><a class="smoothscroll" href="#subscribe">CONTACT</a></li>
     </ul> <!-- end #nav -->

  </nav> <!-- end #nav-wrap -->

  <ul class="header-social">
     <li><a href="#"><i class="fa fa-facebook"></i></a></li>
     <li><a href="#"><i class="fa fa-twitter"></i></a></li>
     <li><a href="#"><i class="fa fa-google-plus"></i></a></li>
  </ul>
  </header> 
<!-- Header End -->

   <!-- Homepage Hero
   ================================================== -->
   <section id="hero">
       <div class="row">
           <div class="twelve columns">
               <div class="hero-text">
                       <br /><br /><br />
                  <h1 class="responsive-headline">Welcome To Alvin's     Limo</h1>
               <p>
                   Little about alivin's limo services.
               </p>
           </div>
                        <br />
        <div class="buttons">
           <a class="button trial"   onclick="openNav()">Reserve Fleet</a>
           <a class="button learn-more smoothscroll"   onclick="openNavv()">Register</a>
        </div>
       <br /><br /><br /><br /><br /><br /><br />
       </div>
   </div>
   </section> 
    <!-- Homepage Hero end -->

在 feature.php 中

   <!-- Features Section
       ================================================== -->
   <section id='features'>
  <div class="row section-head">
       <h1>EVENT TRANSPORTATION</h1>
       <p>
           We Fell Happy To Be Part Of Your Special Ocassion
       </p>
   </div>
  <div class="row feature design">
     <div class="six columns right">
        <h3>  Wedding Transporation</h3>
        <p>LMake your "most memorable day" of your life more special by Alvin Wedding Limo Service. 
         Your weddings transportation will be most beautiful latest model limousine imaginable, 
         with all the special amenities you desire. Our chauffeurs are always on time, courteous, 
         and dressed in black suit. Let us take you to the church and from the church to the reception and 
         from the reception to the airport or any special place in Texas for your honeymoon. You don't need 
         to worry about coordinating transportation from each destination, we can help arrange your weddings 
         party pick-ups and drop-offs and everything in between. We do service all the hills country wedding 
         venues. Feel free to check our wedding reviews - WEDDINGWIRE-THE KNOTT.
        </p>
     </div>
     <div class="six columns feature-media left">
         <img src="images/fpt-112704-Wedding-Flowers.jpg" />            
     </div>
  </div>
  <div class="row feature responsive">
     <div class="six columns left">
        <h3>Wine Transportation.</h3>
        <p>
            Alvin Limousine Services share your passion for wine; that’s why we specialize in hills country
             wine tours. We offer a diverse selection of vehicles ranging from sedans, stretch limousines to 
            transport you affordably in luxury, safety, and style! Leave the driving, directions, stress, 
            and traffic to us while our Chauffeur whisks you away to your perfect day!
            Our impressive customer list is concrete evidence of our ability to outperform our competition, 
            consistently exceeding our customers’ expectations. We will make your tour the best tour you have 
            ever known. We have dedicated chauffeur that specialize in wine tours, Brewery and Vodka distillery.
        </p>
     </div>
     <div class="six columns feature-media right">
         <img src="images/wine-tours-preferrred-limo.jpg" />          
     </div>
  </div>
  <div class="row feature cross-browser">
     <div class="six columns right">
        <h3>Concert</h3>
        <p>
            Whether you want to see a Show, Concert, Opera, Symphony or any other fun thing you can think of, 
            Alvin Limos will provide you personal and reliable chauffeured Limousine. 
            Reserve luxury town car Sedan or our luxurious stretch limousine for hassle free ride 
            from navigation, traffic, and struggling the multitude of cars for parking. Roll up with 
            style to the front door of any events location you desire.
            Let the professional Chauffeurs of Alvin Limousine Service take you to your next Concert, 
            Movie premier, Opera, Symphony or any night out events with comfort and style.
            We get you there on time in safely and in style ; Alvin Limo will ensure you have the time of 
            your life. We are the Leader in providing a full Service Limousine Transportation. 
        </p>
     </div>
     <div class="six columns feature-media left">
         <img src="images/thenextweb.jpg" />
         <!--<img src="images/feature-image-3.png" alt="" />-->
     </div>
  </div>
  <div class="row feature video">
     <div class="six columns left">
        <h3>ACL/SXSW/Austin 360</h3>
        <p>
            What you hear is true. With vibrant entertainment and culture, inspiring cuisine and stunning outdoor settings, Austin lets you create a soundtrack all your own. We're home to more than 250 music venues and a vibrant arts scene. So take a look around, and put Live Music Capital of the World® on your playlist. Whether you want to take ride thought Austin or plan a night out with friends and family we will do that in style. Alvin Limousine is a premier transportation when it comes to Austin Texas culture and events. Come one come all and let us drive though the ins and outs of this beautiful happening city.
            Alvin Limousine staff are very discrete and confident with all our celebrities and movies stars that we have been transporting for years. 
        </p>
     </div>
     <div class="six columns feature-media right">
         <img src="images/1ff7f709cd8ef280ec5f2b317f79ba14-2b32e6b5be7f48f4557299fc9db819c3.png" />           
     </div>
  </div>
   <div class="row feature cross-browser">
       <div class="six columns right">
           <h3>Convention Center</h3>
           <p>
               The Austin Convention Center, a premier facility located in the heart of the capital city’s downtown business district, has emerged as a leader in the convention and meeting industry.
               Alvin’s Limousine Services is proud to be part of your success by providing you or your guests with a premier chauffeured services . We can accommodate small or large groups .
               - Airport Transportations
               - Shuttling your groups through out your meetings
               - Advertising your business on our Cars. (Wrap the cars with your Logo or new Product.**Extra Fees apply)
           </p>
       </div>
       <div class="six columns feature-media left">
           <img src="images/ARATA_ISOZAKI_RHWL_QNCC_DOHA_QATAR_PAN_060313_0009.jpg" />
       </div>
   </div>
   <div class="row feature responsive">
       <div class="six columns left">
           <h3>Circuits of America - Formula 1</h3>
           <p>
               Circuit Of The Americas is a multi-purpose facility that will host the most prestigious racing events in the world, including the Formula 1 United States Grand Prix. It is the first purpose-built Grand Prix facility in the U.S Austin Texas
               Circuit of The Americas (COTA) in Austin, Texas, is the home of world championships and a world-class destination for premium sports and entertainment.
               Alvin’s Limousine Services is proud to be the leading transportations in Austin Texas, we can provide you or your Guests with many VIP Packages that can suits your needs , from Town car service , SUV’s or Stretch Limousine ,we are your one stop solutions to your transportations for World-Class destination . For International reservations , Please use our 24/7 reservations systems for quick quote and complete reservation confirmed within one hour or you can
               Skpe us at : Austinlimo 
           </p>
       </div>
       <div class="six columns feature-media right">
           <img src="images/bQwIzE.jpg" />
       </div>
   </div>
   <div class="row feature cross-browser">
       <div class="six columns right">
           <h3>Prom</h3>
           <p>
               Whether you want to see a Show, Concert, Opera, Symphony or any other fun thing you can think of, Alvin Limos will provide you personal and reliable chauffeured Limousine. Reserve luxury town car Sedan or our luxurious stretch limousine for hassle free ride from navigation, traffic, and struggling the multitude of cars for parking. Roll up with style to the front door of any events location you desire.
               Let the professional Chauffeurs of Alvin Limousine Service take you to your next Concert, Movie premier, Opera, Symphony or any night out events with comfort and style.
               We get you there on time in safely and in style ; Alvin Limo will ensure you have the time of your life. We are the Leader in providing a full Service Limousine Transportation. 
           </p>
       </div>
       <div class="six columns feature-media left">
           <img src="images/prom-header.jpg" />               
       </div>
   </div>
  </section> 
  <!-- Features Section end -->

在 footer.php 中

<!-- Footer
   ================================================== -->
   <footer>
    <div class="row">               
        <div class="six columns right-cols">
           <div class="row">
              <div class="columns">
                <h2 class="address">Come Visit</h2>
                 <p>
                      7901 Cameron Rd Bldg3 Suite 312, Austin tx   78754<br>                  
                 </p>
            </div>
             <div class="columns last">
              <h2 class="contact">Contact Us</h2>
              <ul>
                <li><a href="tel:6473438234">512 300 1379</a></li>

                <li><a href="">someone@woosite.com</a></li>
              </ul>
           </div>
        </div>        
     </div>

    <p class="copyright">&copy; 2014 Alvin's Limousine Services | Design by <a>cts-Design Team</a></p>
     <div id="go-top">
        <a class="smoothscroll" title="Back to Top" href="#hero"><i class="icon-up-open"></i></a>
     </div>
  </div> <!-- Row End -->
  </footer> 
  <!-- Footer End-->
  <?php wp_footer (); ?>
  <!-- Java Script
   ================================================== -->
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2 /jquery.min.js"></script>
  <script>window.jQuery || document.write('<script src="js/jquery-1.10.2.min.js"><\/script>')</script>
  <script type="text/javascript" src="js/jquery-migrate-1.2.1.min.js">    
</script>
  <script src="js/jquery.flexslider.js"></script>
  <script src="js/waypoints.js"></script>
  <script src="js/jquery.fittext.js"></script>
  <script src="js/jquery.fitvids.js"></script>
  <script src="js/imagelightbox.js"></script>
  <script src="js/jquery.prettyPhoto.js"></script>   
  <script src="js/main.js">
 </script>
</body>
</html>

最佳答案

get_header() 和 get_footer() 等函数是预定义的 WordPress 函数。为了获得我们使用的模板的自定义部分

<?php get_template_part( string $slug, string $name = null ) ?>

如文档中所述,它用于查找文件的模式是:

  • {slug}.php
  • {slug}-{name}.php

如果主题不包含指定文件,则不会包含模板。

该模板是使用 require 而不是 require_once 包含的,因此您可以多次包含相同的模板部分。

最后,这应该加载您的功能模板:

<?php get_template_part( 'feature' ) ?>

来源:https://developer.wordpress.org/reference/functions/get_template_part/

关于php get函数在wordpress中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40839517/

相关文章:

javascript - 如何将php中的mysql数据发送到javascript数组

php - PHP中相对路径还是绝对路径以及如何设置

php - mysql数据库的html表单选项值只存储第一个字

html - 粘性页脚显示

css - 元素旋转和transform-style导致显示不一致 : preserve-3d

javascript - 从使用 CodeMirror 创建的内联代码中删除填充

php - 使用 php 给下拉列表一个默认值

php - 使用 codeigniter 调用 mysql 过程 [错误 : result consisted more than one row]

jquery - 图像 slider 自动循环功能

javascript - 在 li 中获取特定图像之上的跨度