wordpress如何設置文章模板

如何在 WordPress 中設置文章模板?創建一個名為 “template-name.php” 的新文件,其中 “template-name” 是您想要的模板名稱。添加代碼 “Template Name: My Custom Template”,其中 “My Custom Template” 是您想要的模板名稱。自定義模板內容,添加您想要顯示的代碼。編輯文章,在 “屬性” 部分將模板分配給文章。

wordpress如何設置文章模板

如何在 WordPress 中設置文章模板

步驟 1:創建文章模板文件

  1. 在您的主題文件夾中創建一個新的文件。
  2. 將文件命名為 “template-name.php”,其中 “template-name” 是您想要的模板名稱。例如: “template-blog.php”。

步驟 2:添加模板代碼

  1. 在您創建的文件中,添加以下代碼:
<?php /* Template Name: My Custom Template */ ?>

替換 “My Custom Template” 為您想要的模板名稱。

步驟 3:自定義模板

  1. 之間添加您想要在模板中顯示的代碼。
  2. 自定義內容、邊欄、頁眉和頁腳,以創建您需要的獨特布局。

步驟 4:將模板分配給文章

  1. 編輯您要使用該模板的文章。
  2. 在側邊欄的 “屬性” 部分,選擇您創建的模板。

示例

要創建一個名為 “Blog 模板” 的模板,請遵循以下步驟:

  1. 創建一個名為 “template-blog.php” 的文件。
  2. 添加以下代碼:
<?php /* Template Name: Blog Template */ ?>
  1. 之間添加以下代碼以顯示文章列表:
<?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(); ?>

現在,您已經為 WordPress 文章創建了一個自定義模板。

? 版權聲明
THE END
喜歡就支持一下吧
點贊13 分享