wordpress主题制作教程,wordpress主题开发手册

上节内容我们已经弄好了博客的页头header.php,今天我们就一起来制作页脚footer.php。footer.php与header.php差不多,写这个文件的目的也是为了精简代码,提高代码的重用性,Aurelius主题目录中的所有页面的页脚代码几乎都是一样的,我们就把这些代码提取出来放到footer.php。

01 制作footer.php|WordPress主题制作全过程6上节内容我们已经弄好了博客的页头header.php,今天我们就一起来制作页脚footer.php。footer.php与header.php差不多,写这个文件的目的也是为了精简代码,提高代码的重用性,Aurelius主题目录中的所有页面的页脚代码几乎都是一样的,我们就把这些代码提取出来放到footer.php。在Aurelius主题目录中新建文件footer.php,我们提取出index.php中的页脚代码拷贝到footer.php中(如果以后你制作自己的主题,可以根据需要决定哪些是footer代码):<!– Footer –><pclass=”grid_12 footer clearfix”> <spanclass=”float”><strong>Design By</strong> QwibbleDesigns&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Code By</strong> <ahref=”http://www.ludou.org/”>Ludou</a></span> <aclass=”float right” href=”#”>top</a> </p></div><!–end wrapper–></body></html>再用文本编辑器打开index.php、archive.php、contact.php、full_width.php、page.php和single.php,删掉以上类似代码,改成:<?php get_footer(); ?>好,现在打开你的博客主页,看看我们制作的主题是否还可以正常工作,答案是可以的,跟原来几乎没什么两样,页脚还是跟原来一样。现在来添加上你的博客版权声明信息和wp_footer()函数,将footer.php中所有代码删除,改成:<!– Footer –><p><span>版权所有 &copy; 2010 <?php bloginfo(‘name’); ?>&nbsp;&nbsp;|&nbsp;&nbsp;Powered By <a rel=”external” title=”WordPress主页” href=”http://wordpress.org/”>WordPress</a>&nbsp;&nbsp;|&nbsp;&nbsp;Design By QwibbleDesigns&nbsp;&nbsp;|&nbsp;&nbsp;Code By <a href=”http://www.ludou.org/”>Ludou</a></span><a href=”#”>top</a> </p></div><!–end wrapper–><?php wp_footer(); ?></body></html>这里用到了我们上次学到的bloginfo('name')函数来输出你的博客标题,wp_footer()和wp_head()差不多,都是用于提高你的主题兼容性,毕竟有很多插件要在页脚输出一些东西才能正常工作。现在你的页脚应该是有模有样了吧,下面是我更改后的效果:footer.php中加入了作者的信息,当然包括我的信息,如果你觉得Code By Ludou这几个字特别碍眼,你可以将其删除,但是请不要删除设计师和WordPress的信息,毕竟这是对他们最起码的尊重!好了,footer.php的制作就这么简单。最后提供经过本次修改后的Aurelius主题文件,你可以用文本编辑器打开看看,跟你修改的文件比较比较,看看你改得怎么样?制作sidebar.php|WordPress主题制作全过程7制作好了header.php 和 footer.php ,今天我们来制作侧边栏sidebar.php。由于侧边栏的可定制性实在是太强了,所以本节内容比较难,我讲解起来也比较困难,有些内容会被略掉!作为各个页面公用的侧边栏,我们还是像制作header.php 和 footer.php那样,从index.php中提取侧边栏,放到sidebar.php。好,现在在你的主题目录Aurelius下新建文件sidebar.php,从index.php中提取一下代码,放到sidebar.php中:<!– Column 2 / Sidebar –><divclass=”grid_4″><h4>Catagories</h4><ulclass=”sidebar”><li><ahref=””>So who are we?</a></li><li><ahref=””>Philosophy</a></li><li><ahref=””>History</a></li><li><ahref=””>Jobs</a></li><li><ahref=””>Staff</a></li><li><ahref=””>Clients</a></li></ul><h4>Archives</h4><ulclass=”sidebar”><li><ahref=””>January 2010</a></li><li><ahref=””>December 2009</a></li><li><ahref=””>Novemeber 2009</a></li><li><ahref=””>October 2009</a></li><li><ahref=””>September 2009</a></li><li><ahref=””>August 2009</a></li></ul></div><divclass=”hr grid_12 clearfix”>&nbsp;</div>再用文本编辑器打开index.php、archive.php、page.php和single.php,删掉以上类似代码,改成:<?php get_sidebar(); ?>好,现在打开你的博客主页,看看我们制作的主题是否还可以正常工作。现在我们的侧边栏还都是静态的代码,大家可能都知道在WordPress后台 – 外观 – 小工具,那里可以拖动你想要的栏目到侧边栏,但是我们的主题目前还不支持这个功能。现在就让我一起来制作完整的sidebar。为了适应WordPress程序,我们还要对sidebar.php做一些微调,下载新的样式表style.css,替换Aurelius目录下的style.css, 开始sidebar.php的制作,我们将在侧边栏放置4个栏目。在初始状态下,也就是你没有在侧边栏放置任何小工具的情况下,这4个栏目自上而下为分类目录、最新文章、标签云和文章月存档。现在将sidebar.php中所有代码删除,改成:<!– Column 2 / Sidebar –><div><?php if ( !function_exists(‘dynamic_sidebar’)|| !dynamic_sidebar(‘First_sidebar’) ) : ?><h4>分类目录</h4><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’) ) : ?><h4>最新文章</h4><ul><?php$posts = get_posts(‘numberposts=6&orderby=post_date’);foreach($posts as $post) {setup_postdata($post);echo ‘<li><a href=”‘ . get_permalink() . ‘”>’ . get_the_title() . ‘</a></li>’;}$post = $posts[0];?></ul><?php endif; ?><?php if ( !function_exists(‘dynamic_sidebar’)|| !dynamic_sidebar(‘Third_sidebar’) ) : ?><h4>标签云</h4><p><?php wp_tag_cloud(‘smallest=8&largest=22′); ?></p><?php endif; ?><?php if ( !function_exists(‘dynamic_sidebar’)|| !dynamic_sidebar(‘Fourth_sidebar’) ) : ?><h4>文章存档</h4><ul><?php wp_get_archives(‘limit=10′); ?></ul><?php endif; ?></div><div>&nbsp;</div>

02 制作index.php|WordPress主题制作全过程8在主页中主要就是文章列表,将你博客上的文章一篇一篇地列出来。你可能已经注意到,主页中每篇文章的样式都是一样的,只是标题、时间、作者和摘要等文字内容不一样而已,嗯!我们制作index.php也只需要一篇文章的html代码,不需要手动地去写那么多文章的html,况且这样也不是动态的内容。我们只需要一个循环就可以将所有文章显示到首页上,循环就是重复做某件事情,这里的循环是重复地输出文章。如果你之前学过任一门计算机程序设计语言的话,就不难理解什么是循环,循环的作用也一想就通,如while,for,foreach……在这里插一句,如果你真的想了解如何制作主题,请打开的文本编辑器,跟着我一步一步地操作,一步一步地修改,每做一次修改就刷新一下你的博客看看有什么变化,这样才能够加深你的理解。如果你懒得动手,建议以后的内容就不用看了,看了对你帮助也不大。现在开始制作index.php。初始情况下index.php中有三篇文章,打开index.php你可以看到文章的3个标记<!-- Blog Post -->,我们现在其他将两篇文章的代码删除,留下一篇,并将文章摘要去除。修改后的代码是这样的:<?php get_header(); ?><!– Column 1 /Content –><divclass=”grid_8″><!– Blog Post –><divclass=”post”><!– Post Title –><h3class=”title”><ahref=”single.html”>Loreum ipsium massa cras phasellus</a></h3><!– Post Data –><pclass=”sub”><ahref=”#”>News</a>, <ahref=”#”>Products</a> &bull; 31st Sep, 09 &bull; <ahref=”#”>1 Comment</a></p><divclass=”hr dotted clearfix”>&nbsp;</div><!– Post Image –><imgclass=”thumb” alt=”” src="/skin/7ke/image/lazy.gif" class="lazy" original="http://www.gxri.com/skin/7ke/image/nopic.gif" bloginfo(‘template_url’); ?>/images/610×150.gif” /><!– Post Content –><!– Read More Button –><pclass=”clearfix”><ahref=”single.html” class=”button right”> Read More…</a></p></div><divclass=”hr clearfix”>&nbsp;</div><!– Blog Navigation –><pclass=”clearfix”> <ahref=”#” class=”button float”>&lt;&lt; Previous Posts</a> <ahref=”#” class=”button float right”>Newer Posts >></a> </p></div><?php get_sidebar(); ?><?php get_footer(); ?>从上面的代码可以看出,一篇文章的html骨架就是:<divclass=”post”><!– Post Title –><h3class=”title”><ahref=”single.html”>文章标题</a></h3><!– Post Data –><pclass=”sub”><ahref=”#”>标签1</a>, <ahref=”#”>标签12</a> &bull; 发布时间 &bull; <ahref=”#”>评论数</a></p><divclass=”hr dotted clearfix”>&nbsp;</div><!– Post Image 文章的缩略图 –><imgclass=”thumb” alt=”” src="/skin/7ke/image/lazy.gif" class="lazy" original="http://www.gxri.com/skin/7ke/image/nopic.gif" bloginfo(‘template_url’); ?>/images/610×150.gif” /><!– Post Content –>文章内容<!– Read More Button –><pclass=”clearfix”><ahref=”single.html” class=”button right”> 阅读全文按钮</a></p></div><divclass=”hr clearfix”>&nbsp;</div>不同主题的主题的文章html骨架是不一样的,如果你熟悉html,可以很快地分辨出文章骨架,以上是我们这个主题的骨架,我们将以此为基础给index.php加上动态内容:

不打算动手编写代码,不想照着本教程一步一步地操作,只是想看看<br/>没有任何网页设计知识<br/>没用过WordPress<br/>非常熟悉WordPress主题制作过程<br/>不喜欢我在此罗嗦

 
举报 0 收藏 0 打赏 0 评论 0
24小时热闻
今日推荐
浙ICP备2022006665号-7