纵有疾风起
人生不言弃

wordpress 主题制作过程

首先准备切好的图的静态文件

1、在themes文件夹新建模板文件夹mythemes

2、把所有静态文件放放入mythemes,把后缀是html改成php,修改样式文件style.css,头部增加:

/*
Theme Name: mythemes
Theme URI: http://www.youwebsite.cn
Description: It’s a theme create by Aze
Version: 1.0
Author: you name
Author URI: you url
Tags: custom header, fixed width, two columns, widgets
*/

/* Global Styles */

放入主题缩略图,然后去后台启动主题。

3、新建header.php和footer.php,把其他文件中相同的头部和底部复制到header.php,footer.php,并用<?php get_header() ; ?>,<?php get_footer() ; ?>  代替

在header.php文件修改title

<title><?php if ( is_home() ) { bloginfo(‘name’); echo ” – “; bloginfo(‘description’); } elseif ( is_category() ) { single_cat_title(); echo ” – “; bloginfo(‘name’); } elseif (is_single() || is_page() ) { single_post_title(); } elseif (is_search() ) { echo “搜索结果”; echo ” – “; bloginfo(‘name’); } elseif (is_404() ) { echo ‘页面未找到!’; } else { wp_title(”,true); } ?></title>

修改样式文件路径:

<link rel=stylesheet href=./style.css type=text/css media=screen />
改为
<link rel=stylesheet href=<?php bloginfo(‘stylesheet_url’); ?> type=text/css media=screen />

修改博客名称和描述:

<h1 id=logo class=grid_4><a href=<?php echo get_option(‘home’); ?>/><?php bloginfo(‘name’); ?></a></h1> <h2 class=grid_12 caption clearfix><?php bloginfo(‘description’); ?></h2>

在</header>前加:

<?php wp_head(); ?>   //加载插件用

添加描述和关键字

<?php $description = ; $keywords = ; if (is_home() || is_page()) { // 将以下引号中的内容改成你的主页description $description = “露兜博客描述”; // 将以下引号中的内容改成你的主页keywords $keywords = “WordPress, 博客, 编程,php,ludou”; } elseif (is_single()) { $description1 = get_post_meta($post>ID, “description”, true); $description2 = str_replace(“\n”,“”,mb_strimwidth(strip_tags($post>post_content), 0, 200, “…”, ‘utf-8’)); // 填写自定义字段description时显示自定义字段的内容,否则使用文章内容前200字作为描述 $description = $description1 ? $description1 : $description2; // 填写自定义字段keywords时显示自定义字段的内容,否则使用文章tags作为关键词 $keywords = get_post_meta($post>ID, “keywords”, true); if($keywords == ) { $tags = wp_get_post_tags($post>ID); foreach ($tags as $tag ) { $keywords = $keywords . $tag>name . “, “; } $keywords = rtrim($keywords, ‘, ‘); } } elseif (is_category()) { // 分类的description可以到后台 – 文章 -分类目录,修改分类的描述 $description = category_description(); $keywords = single_cat_title(, false); } elseif (is_tag()){ // 标签的description可以到后台 – 文章 – 标签,修改标签的描述 $description = tag_description(); $keywords = single_tag_title(, false); } $description = trim(strip_tags($description)); $keywords = trim(strip_tags($keywords)); ?>

<meta name=description content=<?php echo $description; ?> />

<meta name=keywords content=<?php echo $keywords; ?> />

显示菜单:

<ul id=navigation class=grid_8>

<?php wp_list_pages(‘depth=1&title_li=0&sort_column=menu_order’); ?>

<li <?php if (is_home()) { echo ‘class=”current”‘;} ?>><a title=<?php bloginfo(‘name’); ?> href=<?php echo get_option(‘home’); ?>/>主页</a></li>

</ul>

刷新缓存:

<?php flush(); ?>  放在</head>前

4、制作侧边栏。新建sidebar.php

用  <?php get_sidebar(); ?>  替换所有页面侧边部分

把sidebar.php代码修改成:

<!– Column 2 / Sidebar –> <div class=grid_4>

<?php if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(‘First_sidebar’) ) : ?>

<h3>分类目录</h3>

<ul>

<?php wp_list_categories(‘depth=1&title_li=&orderby=id&show_count=0&hide_empty=1&child_of=0’); ?> </ul>

<?php endif; ?>

<?php if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(‘Second_sidebar’) ) : ?>

<h3>最新文章</h3>

<ul>

<?php $posts = get_posts(‘numberposts=6&orderby=post_date’); foreach($posts as $post) { setup_postdata($post); echo ‘<li><a href=”‘%20. get_permalink() . ‘”>’%20. get_the_title() . ‘</a></li>’; } $post = $posts[0]; ?>

</ul>

<?php endif; ?>

<?php if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(‘Third_sidebar’) ) : ?>

<h3>标签云</h3> <p><?php wp_tag_cloud(‘smallest=8&largest=22’); ?></p>

<?php endif; ?>

<?php if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(‘Fourth_sidebar’) ) : ?>

<h3>文章存档</h3>

<ul>

<?php wp_get_archives(‘limit=10’); ?>

</ul>

<?php endif; ?>

</div>

<div class=hr grid_12 clearfix>

</div>

然后下载functions.php,放到主题文件目录下。

5、修改首页index.php

  • <?php the_permalink(); ?>  输出文章的URL链接(参考文档)
  • <?php the_title(); ?>  输出文章的标题(参考文档
  • the_tags(‘标签:’, ‘, ‘, )
  • the_time(‘Y年n月j日’)
  • <?php comments_popup_link(‘0 条评论’, ‘1 条评论’, ‘% 条评论’, , ‘评论已关闭’); ?>
  • <?php edit_post_link(‘编辑’, ‘ • ‘, ); ?>
  • <?php the_excerpt(); ?>   //首页输出摘要
  • <?php the_content(‘阅读全文…’); ?>  //首页输出全文
  • <a href=<?php the_permalink(); ?> class=button right>阅读全文</a>
  • <?php if (have_posts()) : while (have_posts()) : the_post(); ?>添加文章循环<?php endwhile; ?><?php else : ?><h3 class=title><a href=# rel=bookmark>未找到</a></h3> <p>没有找到任何文章!</p> <?php endif; ?>

大概是这样的:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

文章html骨架

<?php endwhile; ?>

<?php else : ?>

输出找不到文章提示

<?php endif; ?>

  • 分页:<?php previous_posts_link(‘<< 查看新文章’, 0); ?> <?php next_posts_link(‘查看旧文章 >>’, 0); ?>

6、文章详情页修改

  • 输出标题:<a href=<?php the_permalink(); ?>><?php the_title(); ?></a>
  • 输出标签:<?php the_tags(‘标签:’, ‘, ‘, ); ?>
  • 输出日期:<?php the_time(‘Y年n月j日’) ?>
  • 输出评论数:<?php comments_popup_link(‘0 条评论’, ‘1 条评论’, ‘% 条评论’, , ‘评论已关闭’); ?>
  • 输出编辑按钮:<?php edit_post_link(‘编辑’, ‘ • ‘, ); ?>
  • 输出文章内容:<?php the_content(); ?>
  • 在标题前面加上:<?php if (have_posts()) : the_post(); update_post_caches($posts); ?>
  • 在侧边栏前面加上:<?php else : ?> <div class=errorbox> 没有文章! </div> <?php endif; ?>

7、修改评论部分

新建公共评论页comments.php

在comments.php加入下面这些代码,防止没有权限的人直接打开

<?php if (isset($_SERVER[‘SCRIPT_FILENAME’]) && ‘comments.php’%20== basename($_SERVER[‘SCRIPT_FILENAME’])) die (‘Please do not load this page directly. Thanks!’); ?>
输出评论列表

<ol class=”commentlist”>
<?php
if (!empty($post->post_password) && $_COOKIE[‘wp-postpass_’ . COOKIEHASH] != $post->post_password) {
// if there’s a password
// and it doesn’t match the cookie
?>
<li class=”decmt-box”>
<p><a href=”#addcomment”>请输入密码再查看评论内容.</a></p>
</li>
<?php
} else if (!comments_open()) {
?>
<li class=”decmt-box”>
<p><a href=”#addcomment”>评论功能已经关闭!</a></p>
</li>
<?php
} else if (!have_comments()) {
?>
<li class=”decmt-box”>
<p><a href=”#addcomment”>还没有任何评论,你来说两句吧</a></p>
</li>
<?php
} else {
wp_list_comments(‘type=comment&callback=aurelius_comment’);
}
?>
</ol>

 

在主题目录下修改functions.php

function aurelius_comment($comment, $args, $depth) { $GLOBALS[‘comment’] = $comment; ?> <li class=comment id=li-comment-<?php comment_ID(); ?>> <div class=gravatar> <?php if (function_exists(‘get_avatar’) && get_option(‘show_avatars’)) { echo get_avatar($comment, 48); } ?> <?php comment_reply_link(array_merge( $args, array(‘reply_text’%20=> ‘回复’,‘depth’%20=> $depth, ‘max_depth’%20=> $args[‘max_depth’]))) ?> </div> <div class=comment_content id=comment-<?php comment_ID(); ?>> <div class=clearfix> <?php printf(__(‘<cite class=”author_name”>%s</cite>’), get_comment_author_link()); ?> <div class=comment-meta commentmetadata>发表于:<?php echo get_comment_time(‘Y-m-d H:i’); ?></div> <?php edit_comment_link(‘修改’); ?> </div> <div class=comment_text> <?php if ($comment>comment_approved == ‘0’) : ?> <em>你的评论正在审核,稍后会显示出来!</em><br /> <?php endif; ?> <?php comment_text(); ?> </div> </div> <?php } ?>

函数名称 函数功能
get_avatar($comment, 48) 获取评论者的gravatar头像,尺寸为48 * 48
comment_reply_link() 回复留言的链接
get_comment_author_link 用于获取评论者博客地址
get_comment_time 获取评论发布时间
edit_comment_link 管理员修改评论的链接
comment_text() 输出评论内容

修改提交评论的表单

<?php
if (!comments_open()) :
// If registration required and not logged in.
elseif (get_option(‘comment_registration’) && !is_user_logged_in()) :
?>
<p>你必须 <a href=”<?php%20echo%20wp_login_url(get_permalink());%20?>”>登录</a> 才能发表评论.</p>
<?php else : ?>
<!– Comment Form –>
<form id=”commentform” name=”commentform” action=”<?php echo get_option(‘siteurl’); ?>/wp-comments-post.php” method=”post”>
<h3>发表评论</h3>
<div class=”hr dotted clearfix”> </div>
<ul>
<?php if (!is_user_logged_in()) : ?>
<li class=”clearfix”>
<label for=”name”>昵称</label>
<input type=”text” name=”author” id=”author” value=”<?php echo $comment_author; ?>” size=”23″ tabindex=”1″ />
</li>
<li class=”clearfix”>
<label for=”email”>电子邮件</label>
<input type=”text” name=”email” id=”email” value=”<?php echo $comment_author_email; ?>” size=”23″ tabindex=”2″ />
</li>
<li class=”clearfix”>
<label for=”email”>网址(选填)</label>
<input type=”text” name=”url” id=”url” value=”<?php echo $comment_author_url; ?>” size=”23″ tabindex=”3″ />
</li>
<?php else : ?>
<li class=”clearfix”>您已登录:<a href=”<?php%20echo%20get_option(‘siteurl’);%20?>/wp-admin/profile.php”><?php echo $user_identity; ?></a>. <a href=”<?php%20echo%20wp_logout_url(get_permalink());%20?>” title=”退出登录”>退出 »</a></li>
<?php endif; ?>
<li class=”clearfix”>
<label for=”message”>评论内容</label>
<textarea id=”message comment” name=”comment” tabindex=”4″ rows=”3″ cols=”40″></textarea>
</li>
<li class=”clearfix”>
<!– Add Comment Button –>
<a href=”javascript:void(0);” onClick=”Javascript:document.forms[‘commentform’].submit()” class=”button medium black right”>发表评论</a> </li>
</ul>
<?php comment_id_fields(); ?>
<?php do_action(‘comment_form’, $post->ID); ?>
</form>
<?php endif; ?>

函数名称 函数功能
is_user_logged_in 判断用户是否登录
wp_login_url 博客登录地址
get_comment_author_link 用于获取评论者博客地址
$comment_author 读取cookie,如果该用户之前已经发表过评论则自动帮助用户填写用户名
$comment_author_email 读取cookie,如果该用户之前已经发表过评论则自动帮助用户填写Email
$comment_author_url 读取cookie,如果该用户之前已经发表过评论则自动帮助用户填写博客地址
do_action(‘comment_form’, $post->ID); 该函数为某些插件预留
wp_logout_url 退出登录的链接

评论页就是这样了

好像都差不多了吧

未经允许不得转载:起风网 » wordpress 主题制作过程
分享到: 生成海报

评论 抢沙发

评论前必须登录!

立即登录