Home > WordPress > wordpress双人主题制作思路

wordpress双人主题制作思路

2009/03/13

前不久看到这个,感觉以后用上又怕找不到,所以找来存档分析。

这个网站(http://rin-wendy.com/)的布局很特别,首页是三栏,左右不同的颜色,文章页根据不同的作者显示不同的颜色,页面又是一种风格。

1. 首先区分页面,首页,作者A和作者B。
<?php if (is_page())  {
$style_item = ‘page’;
} elseif (is_single()) {
if ($post->post_author == ‘1′) {
$style_item = ‘left’;
}
elseif ($post->post_author == ‘2′) {
$style_item = ‘right’;
}
} else {
$style_item = ‘normal’;
} ?>
把定义的$style_item加在DIV框架内,以方便用CSS控制显示。
<div id=”page” class=”wrap-<?php echo($style_item); ?>”>
2. 首页左右作者的实现可以用query_posts来控制
一开始用query_posts(’author=1′ ) 发现这样不能正常分页,查找了相关资料最后找到了如下代码:
<?php
$limit = get_option(‘posts_per_page’);
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
query_posts(‘author=1′ . ‘&paged=’ . $paged);
?>
注意:
<?php endwhile; ?>
下方加上一句
<?php wp_reset_query(); ?>
不加的话会使侧栏的if (is_category())这样的判断失效。
评论部分:
1. 修改comments.php,在wp_list_comments代码那加上&callback=my_comment。
<?php wp_list_comments(‘type=comment&callback=my_comment’); ?>
2. 修改function.php,加入如下代码
function my_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php love_class(); ?> id=”li-comment-<?php comment_ID() ?>”>
<div id=”comment-<?php comment_ID(); ?>”>
<div class=”comment-text”>
<div class=”comment-text-top”>&nbsp;</div>
<?php comment_text() ?>
<?php if ($comment->comment_approved == ‘0′) : ?>
<em><?php _e(‘Your comment is awaiting moderation.’) ?></em>
<?php endif; ?>
<?php edit_comment_link(__(‘(Edit)’),’  ‘,”) ?>
<div class=”comment-text-bot”>&nbsp;</div>
</div>
<div class=”comment-author vcard”>
<?php echo get_avatar($comment,$size=’48′,$default=’<path_to_url>’ ); ?>
<?php printf(__(‘<cite class=”fn”>%s</cite> <span class=”says”>says:</span>’), get_comment_author_link()) ?>
</div>
<div class=”comment-meta commentmetadata”>
<?php printf(__(‘%1$s at %2$s’), get_comment_date(),  get_comment_time()) ?>
</div>
</div>
}
3. function.php,加入如下代码
function love_class( $class = ”, $comment_id = null, $post_id = null, $echo = true ) {
// Separates classes with a single space, collates classes for comment DIV
$class = ‘class=”‘ . join( ‘ ‘, love_comment_class( $class, $comment_id, $post_id ) ) . ‘”‘;
if ( $echo)
echo $class;
else
return $class;
}
function love_comment_class( $class = ”, $comment_id = null, $post_id = null ) {
global $comment_alt, $comment_depth, $comment_thread_alt;
$comment = get_comment($comment_id);
$classes = array();
// Get the comment type (comment, trackback),
$classes[] = ( empty( $comment->comment_type ) ) ? ‘comment’ : $comment->comment_type;
// If the comment author has an id (registered), then print the log in name
if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
// For all registered users, ‘byuser’
$classes[] = ‘byuser comment-author-’ . $user->user_nicename;
// For comment authors who are the author of the post
if ( $post = get_post($post_id) ) {
if ( $comment->user_id === $post->post_author )
$classes[] = ‘bypostauthor’;
}
}
if ( empty($comment_alt) )
$comment_alt = 0;
if ( empty($comment_depth) )
$comment_depth = 1;
if ( empty($comment_thread_alt) )
$comment_thread_alt = 0;
if ( $comment_alt % 2 ) {
if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
$classes[] = ‘odd-’ . $user->user_login;
$classes[] = ‘alt-’ . $user->user_login;
} else {
$classes[] = ‘odd’;
$classes[] = ‘alt’;
}
} else {
if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
$classes[] = ‘even-’ . $user->user_login;
} else {
$classes[] = ‘even’;
}
}
$comment_alt++;
// Alt for top-level comments
if ( 1 == $comment_depth ) {
if ( $comment_thread_alt % 2 ) {
$classes[] = ‘thread-odd’;
$classes[] = ‘thread-alt’;
} else {
$classes[] = ‘thread-even’;
}
$comment_thread_alt++;
}
$classes[] = “depth-$comment_depth”;
if ( !empty($class) ) {
if ( !is_array( $class ) )
$class = preg_split(‘#s+#’, $class);
$classes = array_merge($classes, $class);
}
return apply_filters(‘comment_class’, $classes, $class, $comment_id, $post_id);
}
转自http://www.koryi.net/wp/664.html
说一下我自己的思路:
我当时的想法是:假如有作者A,作者B.那么我们就可以将其定义为class属性名。比如<div class=”A”>然后<div class=”B”>然后通过css来分别控制其显示效果。
而评论留言的区别这个我感觉也没必要考虑。

已经有了14条煽情的读后感

  1. 喜欢博主的主题,看了http://rin-wendy.com,太cool了,我建的博客也是两个人的,我和我女友的,可惜自己不会做主题…唉~~~~

  2. 不错不错,想法不错,代码也不错

  3. 之前看到過,這個想法確實挺有創意的~

  4. 情侣主题,肯定很有市场,完全可以卖了……

  5. 呵呵~
    博主,我现在用你的主题,有几点疑问。
    主题里面的404页面好像跟本没用到,能不能修改下,让主题调用那个404页面呢?
    在IE8下面评论那里也有点小问题,那个框框老是左右移动。

  6. rinwendy很经典的皮
    我在想要不要为了这种情侣皮,去跟一个不是很喜欢的女生谈恋爱呢……

  7. 这个不错 嘿嘿~

  8. 那就是情侣主题咯……..期待ing

  9. 咦?0.0…..评论完以后不是在最高…也不是在最低……竟然还可以插队….哇哈哈o(∩_∩)o

  10. 想和博主做个链接…..呵呵~~~~

  11. 呵呵,我就有个想法做情侣主题,不过等以后有时间了在说了

  12. 呵呵,等待博主的新主题呢,第一时间装博主的主题,哈哈~~~~

  13. 呵呵,那个404页面有作用吧,我自己的都改了,你在改改看是不是哪里出了问题。
    另外谢谢你发现这个问题,因为iE8刚出来不久,还没有发现对其的css hack,所以暂时先放着,等以后研究了在改。

  14. 不要勉强自己,这些东西还是要自己问你自己,祝你幸福 :)

发表感言