2016-08-20 80 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您输入是正确的。

相关问题