How to set up a post template in WordPress? Create a new file called "template-name.php" where "template-name" is the name of your desired template. Add the code "Template Name: My Custom Template", where "My Custom Template" is your desired template name. Customize the template content and add the code you want to display. Edit the article and assign the template to the article in the Properties section.
How to set up a post template in WordPress
Step 1: Create a post template file
Step 2: Add Template Code
<code class="php"><?php /* Template Name: My Custom Template */ ?></code>
Replace "My Custom Template" with your desired template name.
Step 3: Customize the template
<?php get_header(); ?>
and< ;?php get_footer(); ?>
Add the code you want to display in the template. Step 4: Assign the template to the post
Example
To create a template called "Blog Template", follow these steps:
<code class="php"><?php /* Template Name: Blog Template */ ?></code>
<?php get_header(); ?>
and <?php get_footer (); ?>
Add the following code between them to display the post list: <code class="php"><?php $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1; $args = array( 'post_type' => 'post', 'paged' => $paged, ); $query = new WP_Query( $args ); while ( $query->have_posts() ) : $query->the_post(); get_template_part( 'template-parts/content', get_post_format() ); endwhile; wp_reset_postdata(); ?></code>
Now, you have created a custom template for WordPress posts.
The above is the detailed content of How to set up article template in wordpress. For more information, please follow other related articles on the PHP Chinese website!