Wordpress 自定义模板

By hakka. Filed in 技术随笔  |  
Tags: , , ,
TOP

你是不是想不同的页面实现不同的布局呀!

Wordpress 很容易实现。

现在我们就按步骤一步一步来实现吧。

第一步:

使用UltraEdit创建一个文件,就叫mypage.php吧。

第二步(这一步很重要):

在文件头输入下面的固定格式

<?php
/*
Template Name:  yourTemplateName
*/
?>

第三步:

使用Wordpress提供的函数编辑您的模板吧。

第四步:

将文件上传到您正在使用的模板目录下.

第五步:

在Page->Add New的时候,Template项选择您的模板。

第六步:

访问您的新页面,页面布局是否全新展示了:)

gook luck.

例:

<?php
/*
Template Name: Archives with Content
*/
?>
 
<?php get_header(); ?>
 
<div id="content" class="fullcolumn">
 
 <?php if (have_posts()) : while (have_posts()) : the_post();?>
 <div class="post">
  <div class="entrytext">
   <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
  </div>
 </div>
 <?php endwhile; endif; ?>
 
</div>
 
<?php get_footer(); ?>

Leave a Reply