加载中...

顶部、底部模版调用


知识点

get_header页面头部(header.php)
get_footer页面底部(footer.php)

功能实现

在/wp-content/themes/shouce下新建header.php内容如下:

  1. <!doctype html>
  2. <head>
  3. <meta http-equiv="Content-Type"
  4. content="text/html; charset=<?php echo get_bloginfo('charset'); ?>" />
  5. <title><?php bloginfo('name'); ?></title>
  6. <meta name="description" content="<?php bloginfo('description'); ?>" />
  7. <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"
  8. type="text/css" />
  9. <?php wp_head(); ?>
  10. </head>
  11. <body>

在/wp-content/themes/shouce下新建footer.php内容如下:

  1. <div class="c">
  2. <div class="footer">
  3. <p>
  4. 版权所有 <a href="<? bloginfo('url'); ?>"><? bloginfo('name'); ?></a>
  5. </p>
  6. </div>
  7. </div>
  8. <?php wp_footer(); ?>
  9. </body>
  10. </html>

修改/wp-content/themes/shouce/index.php如下:

  1. <?php get_header(); ?>
  2. <div id="header">
  3. <div id="headerimg">
  4. <h1>
  5. <a href="<?php echo get_option('home'); ?>"><?php bloginfo('name'); ?></a>
  6. </h1>
  7. <div class="description"><?php bloginfo('description'); ?></div>
  8. </div>
  9. </div>
  10. <div class="c">
  11. <div id="left-box">
  12. <div id="home-loop">
  13. <?php
  14. if (have_posts ()) {
  15. while ( have_posts () ) {
  16.  
  17. // 获取下一篇文章的信息,并且将信息存入全局变量 $post 中
  18. the_post ();
  19. ?>
  20. <div class="post-item">
  21. <div class="post-title">
  22. <h2>
  23. <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  24. </h2>
  25. </div>
  26. <div class="post-content"><?php the_content(); ?></div>
  27. <div class="post-meta">
  28. 类别:<?php the_category(','); ?><span>|</span>
  29. 作者:<?php the_author(); ?><span>|</span>
  30. 时间:<?php the_time( 'Y-m-d' ); ?>
  31. <?php edit_post_link('修改', ' <span>|</span> ', '' ); ?>
  32. </div>
  33. </div>
  34. <?php
  35. }
  36. } else {
  37. echo '没有日志可以显示';
  38. }
  39. ?>
  40. </div>
  41. <div class="posts_nav_link">
  42. <?php posts_nav_link(); ?>
  43. </div>
  44. </div>
  45. <?php get_sidebar(); ?>
  46. </div>
  47. <?php get_footer(); ?>

效果图:

2015-12-16_231917.gif



还没有评论.