wordpress定制

当前位置: HOME > wordpress > wordpress主题制作系列教程之5

建站,优化,推广

wordpress主题制作系列教程之5

5、funcations.php
自定义函数功能
一般情况下,funcations.php 里面定义的是支持 widget 的 wp 模板的 sidebar
自动生成的 widget 选项的。
<?php
if ( function_exists(‘register_sidebar’) )
register_sidebar(array(
‘before_widget’ => ‘<li id=”%1$s”>’,
‘after_widget’ => ‘</li>’,

));?>

这是用来说明当检测到当前模板支持 widget 时,WordPress 生成的 widget 各选
项会有一个 li 标签围绕,而自动生成的各标题则自动围绕一个 h2 标签。
funcations.php 可以用来定义各种需要的函数,sidebar 只是一个小例子。
6、archives.php
分类功能
分类页面就是 index.php 文件的 <?php if (have_posts()) : ?><?php while
(have_posts()) : the_post(); ?>中间添加一段分类的代码
<?php if (have_posts()) : ?>
<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
<?php /* If this is a category archive */ if (is_category()) { ?>
<h2>Archive for the &#8216;<?php
single_cat_title(); ?>&#8217; Category</h2>(根据 cate 分类)
<?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
<h2>Posts Tagged &#8216;<?php
single_tag_title(); ?>&#8217;</h2>(根据 tag 分类)

<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
<h2>Archive for <?php the_time(‘F jS, Y’); ?></h2>
(根据 day 分类)
<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
<h2>Archive for <?php the_time(‘F, Y’); ?></h2>(根
据 month 分类)
<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
<h2>Archive for <?php the_time(‘Y’); ?></h2>(根据
year 分类)
<?php /* If this is an author archive */ } elseif (is_author()) { ?>
<h2>Author Archive</h2>(根据 author 分类)<?php /* If this is a paged archive */ } elseif (isset($_GET[‘paged’])
&& !empty($_GET[‘paged’])) { ?>
<h2>Blog Archives</h2>(根据 page 分类)
<?php } ?>
<?php while (have_posts()) : the_post(); ?>
7、searchform.php 和 comments.php 
搜索表单和评论功能 
搜索表单和评论功能一般情况下大家可以直接作用默认模板里面的那两个文件,
因为一般情况下这两个文件是不需要改动的。
而调用 cmments.php 则是用这个函数:<?php comments_template();?>:调用留
言板函数

WordPress 主题教程之一

wordpress主题教程之二

wordpress主题教程之三

worpdress主题教程之四

wordpress主题教程之五

wordpress主题教程之六

留下您的宝贵意见

您的电子邮箱地址不会被公开。 必填项已用*标注

12341