2014-09-29 21 views
0

我遇到了一些问题。我的page.php似乎重写了WooCommerce的购物车页面。该页面已被创建(由WooCommerce生成,短代码完好),名为Cart。Woocommerce的购物车页面被我的Page.php页面覆盖在Wordpress中

我知道我的page.php文件被覆盖了,但我不知道如何停止。这里是我的page.php文件页面的代码:

<?php 
get_header(); 

if (have_posts()) { 

    //Work with us page 
    $workwithuspage = "work with us"; 
    $pitch = "pitch an idea"; 
    $cart = "cart"; 

    if($workwithuspage == strtolower(get_the_title())) 
    { 
     //Page stuff here! 
     $image = wpse_get_images(); 
     ?> 
     </div> 
     <div class="hero"> 
      <div class="container heroImage" style="background-image:url('<?php echo $image->guid;?>');"> 
       <div class="col-md-7"></div> 
       <div class="col-md-5"> 
        <div class="pageText"> 
         Work with Us 
        </div> 
        <div class="subText"> 
         <?php echo $image->post_content; ?> 
        </div> 
       </div> 
      </div> 
     </div> 
     <div class="bodyBg"> 
      <div class="container"> 
       <div class="col-md-6"> 
        <div class="box-style"> 
         <div class="box-header"> 
          Got a comic idea and want it published? 
         </div> 
         <div class="box-text"> 
          Tell us your desires, so we can slap it on a comic book and sell it for millions. Ya dig? 
         </div> 
         <div class="box-button-container"> 
          <?php 
           $pitch = get_page_by_title('pitch an idea'); 
          ?> 
          <a href="<?php echo get_permalink($pitch); ?>"><div class="button large">Pitch an Idea</div></a> 
         </div> 
        </div> 
       </div> 
       <div class="col-md-6"> 
        <div class="box-style"> 
         <div class="box-header"> 
          Want to work on one of our great titles? 
         </div> 
         <div class="box-text"> 
          Tell us your desires, so we can slap it on a comic book and sell it for millions. Ya dig? 
         </div> 
         <div class="box-button-container"> 
          <div class="button large">Find Jobs</div> 
         </div> 
        </div> 
       </div> 
      </div> 
     </div> 
     <div id="ourstandards"> 
      <div class="coloroverlay"> 
       <div class="container"> 
        <div class="col-md-6"> 
         <div class="pageHeaderText"> 
          Our Standards 
         </div> 
         <div class="bodyTxt"> 
          <p> 
           At On Target Network, we strive to promote consistency, 
           communication and passion in all areas of work and we expect the same of our artists. 
          </p> 
          <p> 
           We understand the nature of creators and seek to raise ourselves to higher and higher standards. To do that, we vet and 
           review series pitches with a carefully selected panel of writers and artists. 
          </p> 
          <br /><br /> 
          <p> 
           Got questions? We'll be happy to help. 
          </p> 
          <div id="sendUsQ" class="secondaryBtn"> 
           Send us your questions 
          </div> 
         </div> 
        </div> 
        <div class="col-md-6"></div> 
       </div> 
      </div> 
     </div> 
     <div class="container"> 
     <?php 
    } 
    else if($pitch == strtolower(get_the_title())) 
    { 
     ?> 
     </div> 
     <div id="pitchImg" class="hero"> 
      <div class="container"> 
       <div class="col-md-7"></div> 
       <div class="col-md-5"> 
        <div class="pageText"> 
         Pitch an Idea 
        </div> 
        <div class="subText"> 
         <?php echo $image->post_content; ?> 
        </div> 
       </div> 
      </div> 
     </div> 
     <div class="bodyBg"> 
      <div class="container"> 
       <div class="col-md-12"> 
        <div class="pageHeaderText dark"> 
         Start your pitch here 
        </div> 
       </div> 
       <div class="col-md-9"> 
        <?php 
         if (isset($si_contact_form)) { 
          echo $si_contact_form->si_contact_form_short_code(array('form' => '1')); 
         } 
        ?> 
       </div> 
      </div> 
     </div> 
     <?php 
    } 
} 
get_footer(); 
?> 

我有我想自定义页面条件IFS,但我担心在这样做时,它已经覆盖(在某种程度上)的车页面。

回答

1

WooCommerce使用简码添加购物车;简码会显示为页面内容的一部分。 WP使用the_content()函数来显示特定页面或帖子的内容。您已从您的页面模板中删除the_content(),因此购物车不显示。

看你的页面模板,你已删除the_content()和直接内联的所有内容到模板中,而不是从数据库中获取它。这是一个普遍的WP网站的典型例子,但我知道有时一个网站从静态开始,而你只是想把它变成'WP'。

您还使用了一堆条件语句来显示不同的内容块,这是违背使用模板的想法。我的建议是为您的“音调”和“与我们一起工作”页面创建单独的页面模板,并使page.php只是一个默认页面模板,其中包含the_content()。通过这种方式,您可以为任何页面使用通用模板,包括购物车页面。

检查上创建自定义页面模板的详细信息,但简而言之,你添加注释到文件的顶部:

<?php 
/* 
Template Name: My Custom Page 
*/ 

然后将文件保存在你的主题文件夹中。通常的做法是将其命名为page-pitch.php,以便您可以轻松识别它。然后在管理区域中,您可以将模板分配到您想要的任何页面,只需从下拉菜单中选择它即可。

将不同的内容分割成单独的模板有两个好处;即您不再需要使用条件来检查页面标题(这可能因安装而异),并使您更容易进行调试。

+0

你知道,我试图做一个“其他”的声明,看看购物车页面将与'the_content工作()',但是,事实并非如此。 – Majo0od 2014-09-29 21:50:15

+0

我的意思是没有,这是一个空白的页面。 – Majo0od 2014-09-29 21:50:35

+0

另外,是否有创建不同页面模板的最佳做法? – Majo0od 2014-09-29 21:52:13

相关问题