上一篇分析的是情侶模板的基本布局,接下來就是評論部分。主要是判斷非作者、作者A和作者B,還有奇偶的問題。
1. 修改comments.php,在wp_list_comments代碼那加上&callback=my_comment。
1 | <?php wp_list_comments('type=comment&callback=my_comment'); ?> |
這個網站的布局很特別,首頁是三欄,左右不同的顏色,文章頁根據不同的作者顯示不同的顏色,頁面又是一種風格。
1. 首先區分頁面,首頁,作者A和作者B。
1 2 3 4 5 6 7 8 9 10 11 12 | <?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控制顯示。
1 | < div id="page" class="wrap-<?php echo($style_item); ?>"> |