2015-10-13 119 views
0

我在一個WordPress主題中創建了一個計算器,代碼如下所示;在Wordpress主題文件中執行PHP

<?php //Template Name: Quote ?> 
<?php get_header(); ?> 
<section> 
    <div class="container"> 
     <div class="row"> 
      <div class="col-md-12"> 
       <article> 
        <h1><?php the_title(); ?></h1> 
        <div class="post"> 
         <form method="post" action="<?php bloginfo('template_url') ?>/quote.php"> 

          Counter 1: <input type="text" name="counter1width"> x <input type="text" name="counter1depth"><br> 

          <input type="submit" name="submit" value="Calculate Now"> 
         </form> 

         <?php 
          if(isset($_POST["submit"])) { 
           $counter1width = $_POST["counter1width"]; 
           $counter1depth = $_POST["counter1depth"]; 

           echo $counter1width*$counter1depth; 
          } 

         ?> 
        </div> 
       </article> 
      </div> 
     </div> 
    </div> 
</section> 
<?php get_footer(); ?> 

這是錯誤消息我得到...

Fatal error: Call to undefined function get_header() in /home/landford/public_html/wp-content/themes/landfordstone/quote.php on line 2

回答

1

您不能調用qoute.php文件直接。

1) create new page template and in that page template write your code.

2) Create new Page and select the page template from dropdown.

3) Add that page url in form action.