如何在 WordPress 中设置文章模板?创建一个名为 "template-name.php" 的新文件,其中 "template-name" 是您想要的模板名称。添加代码 "Template Name: My Custom Template",其中 "My Custom Template" 是您想要的模板名称。自定义模板内容,添加您想要显示的代码。编辑文章,在 "属性" 部分将模板分配给文章。

如何在 WordPress 中设置文章模板
步骤 1:创建文章模板文件
步骤 2:添加模板代码
<code class="php"><?php /* Template Name: My Custom Template */ ?></code>
替换 "My Custom Template" 为您想要的模板名称。
步骤 3:自定义模板
<?php get_header(); ?> 和 <?php get_footer(); ?> 之间添加您想要在模板中显示的代码。步骤 4:将模板分配给文章
示例
要创建一个名为 "Blog 模板" 的模板,请遵循以下步骤:
<code class="php"><?php /* Template Name: Blog Template */ ?></code>
<?php get_header(); ?> 和 <?php get_footer(); ?> 之间添加以下代码以显示文章列表:<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>现在,您已经为 WordPress 文章创建了一个自定义模板。
以上就是wordpress如何设置文章模板的详细内容,更多请关注php中文网其它相关文章!
全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号