I am wanting to create a page template file to display posts from a custom content type. actually I have 3 different type of post type 'books', 'author' and news. here is my problem these 3 post type have different template and I want to show each of theme in separate pages, first question should I call these post type in a page.php or in single.php? I already know that single.php using for dynamic content and page.php use for static one, what should I create for showing content of these post type? here is an example: I creat page-author.php file to showing author post type here is my code
<?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(); ?>
but it doesn't work. it shows just index page template not what I create for this page. Any suggestions on how to make this post appear ? I completely new to WordPress and this is my first project so I really need help.
You need to create a page from admin and choose the template 'author-page-theme' from the dropdown box that says 'page template'. To show that on frontend, please go to appearance -> menus. then choose the corresponding menu. then drag the newly created page to the selected menu.
$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 );
then var_dump($posts_array);
Also, please check that post_type
you entered is correct.
you can go through custom post type template which is described here: https://codex.wordpress.org/Post_Type_Templates