2016-09-27 126 views
1

我爲wordpress創建了一個自定義主題。當我說'添加新的'頁面,我把內容放入這個頁面時,它只顯示頁腳和頁眉,但是dosnt鉤住了我在該頁面的CMS中的內容。wordpress的自定義主題新頁面

這是我有:page.php文件

<?php get_header(); ?> 

<div class="row"> 
    <div class="col-sm-12"> 

     <?php 
      if (have_posts()) : while (have_posts()) : the_post(); 

       get_template_part('content', get_post_format()); 

      endwhile; endif; 
     ?> 

    </div> <!-- /.col --> 
</div> <!-- /.row --> 

<?php get_footer(); ?> 

它是一個漫長的一天我錯了在這裏做什麼。請提供任何提示?

還想從這個新頁面中製作一個父頁面,但其唯一的選項與頁面屬性是'默認模板'。

+0

好吧,你只加載模板的一部分,這你還沒有使用共享。該模板部分的內容是什麼?此外,我認爲你誤解了[get_post_format](https://codex.wordpress.org/Function_Reference/get_post_format)的作用 - 這不是正確的功能 - 可能你想[get_post_type](https://developer.wordpress.org/reference/functions/get_post_type /),這會導致一個模板名稱爲「content-page.php」 –

回答

0

我的實際問題,已解決。所以我爲我的WordPress使用了「高級自定義字段」插件。使用這個問題的問題是,它仍然需要你做一些編碼。

我添加了一個新頁面。

對於那個頁面我有一個標題圖像和內容。所以對於ACF(高級自定義字段)等於兩個字段類型「圖像 - >字段類型和文本區域 - >字段類型」

字段名稱是我用來調用字段到我的.php頁面模板。

字段名稱:圖片=頭圖像

字段名稱:(2)文本區=頭圖像文本頂部(和)頭圖像-文本作者

(我需要在圖像上顯示我的文字,這就是爲什麼我的div只是基於標題圖像。)

所以我迷上了我的頁面模板,然後添加了我想在此頁面模板上顯示的字段的鉤子。

頁stay.php:

<?php 
    /*Template Name: Stay - Parent Page */ 
    get_header(); ?> 



<div id="primary" class="content-area"> 
    <main id="main" class="site-main" role="main"> 

    <?php 
    // Start the loop. 
    while (have_posts()) : the_post(); ?> 

    <article id="post=<?php the_ID(); ?>" <?php post_class(); ?>> 

     <!-- <header class="entry-header"> 
      <?php the_title('<h1 class="entry-title">', '</h1>'); ?> 
     </header>(you can use this if you need your page header to display)--> 

     <div class="enry-content"> 
     <?php 
     $image = get_field('header-image'); 

      if(!empty($image)): ?> 
      <div class="head-image"> 
      <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" /> 
       <div class="head-text-box"> 
        <div class="head-text-box-holder"> 
         <p class="headtext-quote"><?php the_field('header-image-text-top'); ?></p> 
         <p class="headtext-author"><?php the_field('header-image-text-bottom'); ?></p> 
        </div> 
       </div> 
      </div> 
     <?php endif; ?> 

    </article> 

    <?php endwhile; ?> 

    </main><!-- .site-main --> 
</div><!-- .content-area --> 

<?php get_footer(); ?> 
0

如果您沒有模板部件,請使用the_content()而不是 get_template_part('content',get_post_format());