2016-08-20 82 views
-1

我想要創建頁面模板文件以顯示來自自定義內容類型的帖子。實際上我有3種不同類型的帖子類型'書籍','作者'和新聞。 這裏是我的問題這3個職位類型有不同的模板,我想顯示在不同的頁面中的每個主題,第一個問題應該在page.php或single.php中調用這些職位類型?我已經知道single.php用於動態內容,page.php用於靜態內容,我應該創建什麼來顯示這些帖子類型的內容? 這裏有一個例子: 我創造頁面author.php文件顯示作者崗位類型 這裏是我的代碼如何創建頁面模板以顯示自定義帖子類型

<?php /* Template Name: author-page-theme */ 
    get_header(); ?> 
<div class="head-style col-md-12 col-sm-12 col-xs-12"> 
    <?php while (have_posts()) : the_post(); ?> 
    <div class="title-pack col-md-12 col-sm-12 col-xs-12"> 
     <span class="line visible-sm-block"></span> 
     <span class="visible-sm-block tittle-style"><?php the_title(); ?></span> 
    </div> 
    <div class="row writer-crit"> 
     <div class="writer-crit-box col-md-9 col-sm-8 col-xs-12"> 
      <div class="col-md-11 col-sm-11 col-xs-12"> 
       <?php $args = array('post_type' => 'Author', 'posts_per_page' => 5); 
       $loop = new WP_Query($args); 
       while ($loop->have_posts()) : $loop->the_post(); ?> 
        <a class="writer-link col-md-12 col-sm-12 col-xs-12" href="<?php post_permalink(); ?>"> 
         <div class="writer-row1 col-md-12 col-sm-12 col-xs-12"> 
          <div class="col-md-2 col-sm-3 col-xs-12 image-right"> 
           <?php the_post_thumbnail(array('class' => 'img-responsive')); ?> 
          </div> 
          <div class="col-md-10 col-xs-12 col-sm-9 col-xs-12 pull-right writer-content"> 
           <h3><?php the_title(); ?></h3> 
           <?php if (get_field('auth-trans')) { 
            echo '<h4>'.get_field('auth-trans').'</h4>';} ?>  
           <?php if (get_field('writer-bio')) { 
            echo '<p>'.get_field('writer-bio').'</p>';} ?> 

           <span>...</span> 
          </div> 
         </div> 
        </a> 
       <?php endwhile; // End of the loop. ?>            
      </div> 
     </div> 
    <?php endwhile; // End of the loop. ?> 
    </div> 
<?php get_footer(); ?> 

,但它不工作。它只顯示索引頁面模板,而不是我爲此頁面創建的內容。 關於如何讓這個帖子出現的任何建議? 我完全不熟悉WordPress,這是我的第一個項目,所以我非常需要幫助。

+0

@Prabin Parajuli u能幫助我解決這個問題呢? – mkafiyan

回答

0

您需要從admin創建一個頁面,然後從顯示'頁面模板'的下拉框中選擇模板'author-page-theme'。要在前端顯示,請轉到外觀 - >菜單。然後選擇相應的菜單。然後將新創建的頁面拖到選定的菜單中。

+0

我以前做過,但不起作用。我以爲它是動態的,不應該在頁面上顯示它。 – mkafiyan

0
$args = array(

    'posts_per_page' => 5, 
    'offset'   => 0, 
    'category'   => '', 
    'category_name' => '', 
    'orderby'   => 'date', 
    'order'   => 'DESC', 
    'include'   => '', 
    'exclude'   => '', 
    'meta_key'   => '', 
    'meta_value'  => '', 
    'post_type'  => 'Author', 
    'post_mime_type' => '', 
    'post_parent'  => '', 
    'author'  => '', 
    'author_name'  => '', 
    'post_status'  => 'publish', 
    'suppress_filters' => true 
); 

$posts_array = get_posts($args); 

然後var_dump($posts_array);

另外,請檢查post_type您輸入是正確的。

相關問題