我們在制作page頁面時經常會調用特定的頁面模板,比如專題頁,其實我們只要做一個這樣的模板就可以了,很簡單,定義一下,代碼如下,Template Name: service就是具體的頁面模板名,這個在后面網站后台選擇模板會用到,我們把這個文件命名為page-service.php,上傳到page.php相同目錄,/wp-content/themes/ytkah/,ytkah是網站的主題名
<?php /** * Template Name: service */ ?> <?php get_header(); ?> <main class="service"> <div class="container"> <?php if(have_posts()) : ?> <?php while(have_posts()) : the_post(); ?> <div class="banner"> <h1><?php the_title(); ?></h1> </div> <div class="item"> <h2><?php the_title(); ?></h2> <hr> <?php the_content(); ?> </div> <?php endwhile; ?> <?php endif; ?> </div> </main> <?php get_footer(); ?>
現在我們到網站后台,新建一個service頁面,在右側的頁面屬性中的模板,我們選service,就是剛剛定義的Name
更新一些內容,然后保存提交,再去查看這個頁面是不是已經變成你想要的樣子了