wordpress如何调用特定页面模板
我们在制作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
更新一些内容,然后保存提交,再去查看这个页面是不是已经变成你想要的样子了
加微信交流