好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

如何制作wordpress模板 - WordPress

如何制作wordpress模板

有时候自己看到一个非常好的网站,但是没有模板,这个时候该怎么办呢?其实,在后知的这个博客的边栏是自己仿出来的,所以这里教大家如何用wp仿站制作模板,后知也是在学习中愿与大家一起学习制作.

首先,我们来进行对wordpress模板结构分析

索引页模版:index.php

顶部:header.php

文章页面模板:single.php

边栏模板:sidebar.php

底部:footer.php

页面模版:page.php

搜索结果:search.php

文章归档:archive.php

评论:comments.php

404 页面模版:404.php

主题支持函数:functions.php

样式表:style.css

然后,制作一个可以运行的wordpress主题,修改style.css

制作一个最简单的主题,只需要两个文件,index.php和style.css

第一步, 准备静态页面

第二步, 制作index.php和style.css

第三步, 给style.css添加版权信息

第四步, 把主题上传到空间中wordpress安装路径,wp-content/themes/下面,这里主题的文件夹名字必须是英文

第五步, 在wordpress后台启用主题

先给style.css添加版权信息

所以的images都要换成<?php bloginfo('template_directory'); ?>/images

Style.css路径调用:<?php bloginfo( 'stylesheet_url' ); ?>

主题缩略图名字:screenshot.png

再制作出主题结构,index.php,header.php,footer.php,sidebar.php

把index.php拆分成header.php,footer.php和sidebar.phhp

<?php get_header();?>  <?php get_footer();?>  <?php get_sidebar();?> 

还有就是,修改header.php,footer.php

新建一个index.php文件,header.php,footer.php,

这步需要用到的标签:

获取博客名字: <?php bloginfo('name'); ?>

获取博客描述: <?php bloginfo('description'); ?>

获取主页路径: <?php echo get_option('home'); ?>

获取主题存放路径: <?php bloginfo('template_directory'); ?>

其他外部文件调用方法: <?php include (TEMPLATEPATH . '/ad/ad2.htm'); ?>

<meta http-equiv= "Content-Type"  content= "text/html; charset=<?php bloginfo( 'charset' ); ?>"  />  <?php wp_head(); ?>  <title><?php  if  (is_home()||is_search()) { bloginfo( 'name' ); }  else  { wp_title( '' ); print  " - " ; bloginfo( 'name' ); } ?> </title> 

页面调用:

<?php wp_list_pages('sort_column=menu_order&title_li=&depth=2&include='); ?>

分类目录调用:

<?php wp_list_categories('title_li=0&orderby=name&show_count=0&depth=2'); ?>

如果当前文章所属分类为两个以上还可以格式化输出它们:

<?php the_category( '-' )?>

这样就会输出这样的内容 [分类1 - 分类2 - 分类3 - ......]

<p>当前位置: <a href= "http://xxx.com/"  title= "首页" >首页</a>&gt;&gt;<?php  $categorys  = get_the_category();  $category  =  $categorys [0]; echo (get_category_parents( $category ->term_id,true, '>>' )); ?> 阅读正文</p> 

还有就是跟后知博客的边栏一样,制作sidebar.php

最新文章: <?php wp_get_archives('type=postbypost&limit=20'); ?>

日志标题太长超出,修改style.css,用到的代码:

text-overflow:ellipsis; W*hite-space:nowrap; overflow:hidden;

随机文章:

<?php rand_posts  as   $post ) : ?>  <li><a href= "<?php the_permalink(); ?>" ><?php the_title(); ?></a></li>  <?php  endforeach ;?> 

不用Random Pages Widget插件实现随机文章的写法

<?php  $rand_posts  = get_posts( 'numberposts=5&orderby=rand' );  foreach (  $rand_posts   as   $post  ) : ?>  <li><a href= "<?php the_permalink(); ?>" ><?php the_title(); ?></a></li>  <?php  endforeach ; ?> 

标签云: <?php wp_tag_cloud('smallest=8&largest=36&'); ?>

文章日期归档: <?php wp_get_archives( 'type=monthly' ); ?>

分类目录: <?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?>

友情链接: <?php wp_list_bookmarks('title_li=&categorize=0&orderby=rand&limit=24'); ?>

友情链接调用函数,以下调用类别id为45的友情链接

<?php get_links( "45" ,  "<li>" ,  "</li>" ,  "<br>" , FALSE,  "id" , FALSE, FALSE, -1, FALSE);?> 

在进行对index.php的制作:

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

标题: <a href="<?php the_permalink() ?>"><?php the_title_attribute(); ?></a>

调用文章内容: <?php the_content("Read More..."); ?>

调用文章内容摘要: <?php the_excerpt("Read More..."); ?>

作者: <?php the_author_posts_link(); ?>

日期: <?php the_time('F d, Y') ?>

评论调用: <?php comments_number('No Comment', '1 Comment', '% Comments' );?>

文章所属分类: 标签:<?php the_category(', ') ?>

上一页,下一页调用:

<div style= "float:left" ><?php previous_post_link( '&laquo; %link' ); ?></div>  <div style= "float:right" ><?php next_post_link( '%link &raquo;' ); ?></div> 

最后,制作single.php页面,加入评论:

在single.php中调用<?php endwhile; ?>和<?php else : ?>中间让入

<?php comments_template(); ?>

这样就能够简单的制作出来一个模板了,后知愿与大家一起分享.

查看更多关于如何制作wordpress模板 - WordPress的详细内容...

  阅读:128次