情侣模板的制作思路

2009年11月23日  |  21:56 | 分类:随感  |  作者:小白 | 432 views

rin-wendy.com情侣模板的制作思路(一)

这个网站的布局很特别,首页是三栏,左右不同的颜色,文章页根据不同的作者显示不同的颜色,页面又是一种风格。

1. 首先区分页面,首页,作者A和作者B。

  1. <?php if (is_page())  {
  2. $style_item = ‘page’;
  3. } elseif (is_single()) {
  4. if ($post->post_author == ‘1′) {
  5. $style_item = ‘left’;
  6. }
  7. elseif ($post->post_author == ‘2′) {
  8. $style_item = ‘right’;
  9. }
  10. } else {
  11. $style_item = ‘normal’;
  12. } ?>

把定义的$style_item加在DIV框架内,以方便用CSS控制显示。

  1. <div id=”page” class=”wrap-<?php echo($style_item); ?>”>

2. 首页左右作者的实现可以用query_posts来控制
一开始用query_posts(’author=1′ ) 发现这样不能正常分页,查找了相关资料最后找到了如下代码:

  1. <?php
  2. $limit = get_option(’posts_per_page’);
  3. $paged = (get_query_var(’paged’)) ? get_query_var(’paged’) : 1;
  4. query_posts(’author=1′ . ‘&paged=’ . $paged);
  5. ?>

注意:

  1. <?php endwhile; ?>

下方加上一句

  1. <?php wp_reset_query(); ?>

不加的话会使侧栏的if (is_category())这样的判断失效。

rin-wendy.com情侣模板的制作思路(二)

上一篇分析的是情侣模板的基本布局,接下来就是评论部分。主要是判断非作者、作者A和作者B,还有奇偶的问题。

1. 修改comments.php,在wp_list_comments代码那加上&callback=my_comment。

  1. <?php wp_list_comments(’type=comment&callback=my_comment’); ?>

2. 修改function.php,加入如下代码

  1. function my_comment($comment, $args, $depth) {
  2. $GLOBALS['comment'] = $comment; ?>
  3. <li <?php love_class(); ?> id=”li-comment-<?php comment_ID() ?>”>
  4. <div id=”comment-<?php comment_ID(); ?>”>
  5. <div class=”comment-text”>
  6. <div class=”comment-text-top”>&nbsp;</div>
  7. <?php comment_text() ?>
  8. <?php if ($comment->comment_approved == ‘0′) : ?>
  9. <em><?php _e(’Your comment is awaiting moderation.’) ?></em>
  10. <?php endif; ?>
  11. <?php edit_comment_link(__(’(Edit)’),’  ‘,”) ?>
  12. <div class=”comment-text-bot”>&nbsp;</div>
  13. </div>
  14. <div class=”comment-author vcard”>
  15. <?php echo get_avatar($comment,$size=’48′,$default=’<path_to_url>’ ); ?>
  16. <?php printf(__(’<cite class=”fn”>%s</cite> <span class=”says”>says:</span>’), get_comment_author_link()) ?>
  17. </div>
  18.  
  19. <div class=”comment-meta commentmetadata”>
  20. <?php printf(__(’%1$s at %2$s’), get_comment_date(),  get_comment_time()) ?>
  21. </div>
  22. </div>
  23. }

3. function.php,加入如下代码

  1. function love_class( $class = ”, $comment_id = null, $post_id = null, $echo = true ) {
  2. // Separates classes with a single space, collates classes for comment DIV
  3. $class = ‘class=”‘ . join( ‘ ‘, love_comment_class( $class, $comment_id, $post_id ) ) . ‘”‘;
  4. if ( $echo)
  5. echo $class;
  6. else
  7. return $class;
  8. }
  9.  
  10. function love_comment_class( $class = ”, $comment_id = null, $post_id = null ) {
  11. global $comment_alt, $comment_depth, $comment_thread_alt;
  12.  
  13. $comment = get_comment($comment_id);
  14.  
  15. $classes = array();
  16.  
  17. // Get the comment type (comment, trackback),
  18. $classes[] = ( empty( $comment->comment_type ) ) ? ‘comment’ : $comment->comment_type;
  19.  
  20. // If the comment author has an id (registered), then print the log in name
  21. if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
  22. // For all registered users, ‘byuser’
  23. $classes[] = ‘byuser comment-author-’ . $user->user_nicename;
  24. // For comment authors who are the author of the post
  25. if ( $post = get_post($post_id) ) {
  26. if ( $comment->user_id === $post->post_author )
  27. $classes[] = ‘bypostauthor’;
  28. }
  29. }
  30.  
  31. if ( empty($comment_alt) )
  32. $comment_alt = 0;
  33. if ( empty($comment_depth) )
  34. $comment_depth = 1;
  35. if ( empty($comment_thread_alt) )
  36. $comment_thread_alt = 0;
  37.  
  38. if ( $comment_alt % 2 ) {
  39. if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
  40. $classes[] = ‘odd-’ . $user->user_login;
  41. $classes[] = ‘alt-’ . $user->user_login;
  42. } else {
  43. $classes[] = ‘odd’;
  44. $classes[] = ‘alt’;
  45. }
  46. } else {
  47. if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
  48. $classes[] = ‘even-’ . $user->user_login;
  49. } else {
  50. $classes[] = ‘even’;
  51. }
  52. }
  53. $comment_alt++;
  54.  
  55. // Alt for top-level comments
  56. if ( 1 == $comment_depth ) {
  57. if ( $comment_thread_alt % 2 ) {
  58. $classes[] = ‘thread-odd’;
  59. $classes[] = ‘thread-alt’;
  60. } else {
  61. $classes[] = ‘thread-even’;
  62. }
  63. $comment_thread_alt++;
  64. }
  65.  
  66. $classes[] = “depth-$comment_depth”;
  67.  
  68. if ( !empty($class) ) {
  69. if ( !is_array( $class ) )
  70. $class = preg_split(’#\s+#’, $class);
  71. $classes = array_merge($classes, $class);
  72. }
  73.  
  74. return apply_filters(’comment_class’, $classes, $class, $comment_id, $post_id);
  75. }

喜欢本文,那就收藏到: Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网

4条评论 关于 “情侣模板的制作思路”

  1. 山东网站优化 发表于: 十一月 24th, 2009 13:49

    山东网站优化(www.shandong-seo.cn)前来学习,网站很好,有空多多交流。

    Reply

  2. 山东网站优化 发表于: 十一月 24th, 2009 15:49

    内容很好,能学到好多东西,收藏了,博主别见怪啊。

    Reply

  3. 视频聊天室 发表于: 十一月 25th, 2009 01:35

    博客不错!

    Reply

  4. 请勿 发表于: 十二月 8th, 2009 12:46

    http://www.lovekme.com
    想要情侣模板,,没找到满意的。。很郁闷

    Reply


发表您的评论