WordPress Theme Development 18 – Home Page Template

Do you notice any different on my home page? Yes. It is not longer very static informations. It does have a brief introduction. Of course, that is static. Then there are two parts that are dynamic information. The first one is the recent posts of my blog. The second one is some random images from my gallery. How these can be done? You can refer to the references below. The final home page template is shown as below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  1. <?php
  2. /**
  3. * @package WordPress
  4. * @subpackage Your_Theme
  5. */
  6. /*
  7. Template Name: Home
  8. */
  9. get_header(); ?>
  10. <div id="container">
  11. <div id="content">
  12. <div class="entry-title">
  13. <h2>Welcome</h2>
  14. </div><!-- .entry-title -->
  15. <div class="entry-content">
  16. <p>This place for sharing the things that I know. Hope you guys like it.</p>
  17. </div><!-- .entry-content -->
  18. <div class="entry-title">
  19. <h2><a href="./blog/" title="Blog">Blog</a>: What's Fresh</h2>
  20. </div><!-- .entry-title -->
  21. <div class="entry-content">
  22. <ul>
  23. <?php
  24. $how_many=8; //How many posts do you want to show
  25. $news=$wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts
  26. WHERE `post_type`=\"post\" AND `post_status`= \"publish\" ORDER BY `post_date` DESC LIMIT $how_many");
  27. foreach($news as $np){
  28. printf ("<li><a href=\"index.php?p=%s\">%s</a></li>", $np->ID,$np->post_title);
  29. }
  30. ?>
  31. </ul>
  32. </div><!-- .entry-content -->
  33. <?php
  34. $number_of_pic=18;
  35. $Width=60;
  36. $Height=60;
  37. if (function_exists("nggDisplayRandomImages")) {
  38. ?>
  39. <div class="entry-title">
  40. <h2><a href="./gallery/" title="Gallery">Gallery</a>: Random Images</h2>
  41. </div><!-- .entry-title -->
  42. <?php
  43. nggDisplayRandomImages($number_of_pic,$Width,$Height);
  44. }
  45. ?>
  46. </div><!-- #content -->
  47. </div><!-- #container -->
  48. <?php get_sidebar(); ?>
  49. <?php get_footer(); ?>

References

No Comments

No comments yet.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">