這個網站的布局很特別,首頁是三欄,左右不同的顏色,文章頁根據不同的作者顯示不同的顏色,頁面又是一種風格。
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); ?>"> |
2. 首頁左右作者的實現可以用query_posts來控制
一開始用query_posts(‘author=1’ ) 發現這樣不能正常分頁,查找了相關資料最后找到了如下代碼:
1 2 3 4 5 | <?php $limit = get_option('posts_per_page'); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('author=1' . '&paged=' . $paged); ?> |
注意:
1 | <?php endwhile; ?> |
下方加上一句
1 | <?php wp_reset_query(); ?> |
不加的話會使側欄的if (is_category())這樣的判斷失效。
這樣基本的布局就完成。下一篇分析情侶模板的評論部分