Create Custom Template for WordPress page
xxxxxxxxxx
<?php
/**
* Template Name: Name_of_template_goes_here
*/
?>
<?php get_header(); ?>
// Code Goes here...
<?php get_footer(); ?>
Create a php file in your theme folder and add the above to your file and give it an appropriate name.
xxxxxxxxxx
/* make this file in template-parts folder
give file name as category_post.php */
<?php
/**
* Template Name: Category Custom Page
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'category_name' => 'wordpress',
'posts_per_page' => 5,
);
$arr_posts = new WP_Query( $args );
if ( $arr_posts->have_posts() ) :
while ( $arr_posts->have_posts() ) :
$arr_posts->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
if ( has_post_thumbnail() ) :
the_post_thumbnail();
endif;
?>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<div class="entry-content">
<?php the_excerpt(); ?>
<a href="<?php the_permalink(); ?>">Read More</a>
</div>
</article>
<?php
endwhile;
wp_pagenavi(
array(
'query' => $arr_posts,
)
);
endif;
?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<?php get_footer(); ?>
xxxxxxxxxx
<?php /* Template Name: Name of template */ ?>
// OR
<?php
/**
* Template Name: Name of template
*
* @package WordPress
* @subpackage Twenty_Twenty
* @since Twenty Twenty 1.0
*/
xxxxxxxxxx
<?php
/*
Template Name: Custom Template
*/
get_header(); // Include the header.php file
if (have_posts()) {
while (have_posts()) {
the_post(); // Set up the current post
// Display post content
the_content();
// Custom template code goes here
}
}
get_footer(); // Include the footer.php file
?>