修改wp cms主题green-island
2009 四月 12
小新同志说要把论坛放到分站 bbs.fengyeting.cn
主站改用wp 做cms .
在WP官网down 了wp cms主题green-island.[下载地址:http://wordpress.org/extend/themes/green-island]
1.在header.php文件的
1 | <li <?php if(is_home()) { echo ' class="current_page_item"'; } ?>><a href="<?php bloginfo('siteurl'); ?>">Home</a></li> |
下添加
1 2 | <li><a href="http://bbs.fengyeting.cn/" target="_BLANK">论坛</a></li> <li><?php wp_list_categories('show_count=1&title_li=&show_count=0'); ?></li> |
这样顶部导航栏就有栏目分类了.
2.让WP调用discuz 论坛的数据,在侧边栏自动调用dz数据,生成 “最新帖子”|”最新回复”|”热门帖子”
下面是我修改后的 sidebar.php
$bbsURL 是论坛的地址 [我这里只是本地测试,文件中有的变量要自己根据具体情况改]
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | <div id="sidebar"> <div id="sidebar_main"> <?php if(function_exists(dynamic_sidebar)) dynamic_sidebar(); ?> <?php require_once('D:\htdocs\wordpress\wp-load.php'); //wp-load.php文件,路径自己根据具体情况改 $bbsURL='http://127.0.0.1/dz7/bbs/'; //论坛URL路径自己根据具体情况改 $dateformat='Y-m-d'; $timeformat='h:m:s'; $timeoffset=8; $dztablepre='cdb_'; //discuz论坛表前缀 global $wpdb; ///////////////////////////////////////////////////////////// function gbk2utf8($str) { if(function_exists(iconv)) { $str=iconv("GBK", "UTF-8",$str); } else if(function_exists(mb_convert_encoding)) { $str=mb_convert_encoding($str,"UTF-8","GBK"); //GBK 编码的转成UTF-8编码 } else { echo "<script>alert('您的服务器不支持相应的的函数(iconv,mb_convert_encoding等),程序不行继续运行~!');</scritp>"; } return $str; } function cutstr($string, $length, $dot = ' ...') { global $charset; if(strlen($string) <= $length) { return $string; } $string = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $string); $strcut = ''; if(strtolower($charset) == 'utf-8') { $n = $tn = $noc = 0; while($n < strlen($string)) { $t = ord($string[$n]); if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) { $tn = 1; $n++; $noc++; } elseif(194 <= $t && $t <= 223) { $tn = 2; $n += 2; $noc += 2; } elseif(224 <= $t && $t <= 239) { $tn = 3; $n += 3; $noc += 2; } elseif(240 <= $t && $t <= 247) { $tn = 4; $n += 4; $noc += 2; } elseif(248 <= $t && $t <= 251) { $tn = 5; $n += 5; $noc += 2; } elseif($t == 252 || $t == 253) { $tn = 6; $n += 6; $noc += 2; } else { $n++; } if($noc >= $length) { break; } } if($noc > $length) { $n -= $tn; } $strcut = substr($string, 0, $n); } else { for($i = 0; $i < $length; $i++) { $strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i]; } } $strcut = str_replace(array('&', '"', '<', '>'), array('&', '"', '<', '>'), $strcut); return $strcut.$dot; } ////////////////////////////////////////////////////////////////////////////////////////////////// //新贴 $colorarray = array('', 'red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple', 'gray'); $hack_cut_str = 26; //标题字数 $hack_cut_strauthor = 9; $new_post_threadlist = array(); $nthread = array(); // $query=$wpdb->query("SELECT t.*, f.name FROM {$dztablepre}threads t, {$dztablepre}forums f WHERE f.fid=t.fid AND t.displayorder not in (-1,-2) ORDER BY t.dateline DESC LIMIT 0, 10"); $wpdb->query("SET NAMES 'gbk'"); $query="SELECT t.*, f.name FROM {$dztablepre}threads t, {$dztablepre}forums f WHERE f.fid=t.fid AND t.displayorder not in (-1,-2) ORDER BY t.dateline DESC LIMIT 0, 10"; if($nthread = $wpdb->get_results($query,ARRAY_A)) { //print_r($nthread);die(); foreach($nthread as $key =>$data) { if($data['tid']) { //$nthread[$key]['tid']=$data['tid']; $nthread[$key]['forumname'] = gbk2utf8(ereg_replace('<[^>]*>','',$data['name'])); $nthread[$key]['subject']=gbk2utf8($data['subject']); $nthread[$key]['view_subject'] = gbk2utf8(cutstr($data['subject'],$hack_cut_str)); $nthread[$key]['author'] =gbk2utf8($data['author']); $nthread[$key]['view_author'] = gbk2utf8(cutstr($data['author'],$hack_cut_strauthor)); $nthread[$key]['view_lastposter']=gbk2utf8(cutstr($data['lastposter'],$hack_cut_strauthor)); $nthread[$key]['lastreplytime']= gmdate("$dateformat $timeformat", $data['lastpost'] + ($timeoffset * 3600)); if($nthread[$key]['highlight']) { $string = sprintf('%02d', $data['highlight']); $stylestr = sprintf('%03b', $string[0]); $nthread[$key]['highlight'] = 'style="'; $nthread[$key]['highlight'] .= $stylestr[0] ? 'font-weight: bold;' : ''; $nthread[$key]['highlight'] .= $stylestr[1] ? 'font-style: italic;' : ''; $nthread[$key]['highlight'] .= $stylestr[2] ? 'text-decoration: underline;' : ''; $nthread[$key]['highlight'] .= $string[1] ? 'color: '.$colorarray[$string[1]] : ''; $nthread[$key]['highlight'] .= '"'; } else { $nthread[$key]['highlight'] = ''; } //$new_post_threadlist =&$nthread; } } } //print_r($new_post_threadlist);die(); //新回复 $hack_cut_str = 26; //标题字数 $hack_cut_strauthor = 9; $new_reply_threadlist = array(); $rthread = array(); $query="SELECT t.*, f.name FROM {$dztablepre}threads t, {$dztablepre}forums f WHERE f.fid=t.fid AND t.displayorder not in (-1,-2) AND t.closed NOT LIKE 'moved|%' AND t.replies !=0 ORDER BY t.lastpost DESC LIMIT 0, 10"; if($rthread = $wpdb->get_results($query,ARRAY_A)) { foreach($rthread as $key =>$data) { if($data['tid']) { $rthread[$key]['forumname'] =gbk2utf8( ereg_replace('<[^>]*>','',$data['name'])); $rthread[$key]['view_subject'] =gbk2utf8( cutstr($data['subject'],$hack_cut_str)); $rthread[$key]['subject']=gbk2utf8($data['subject']); $nthread[$key]['author'] =gbk2utf8($data['author']); $rthread[$key]['view_author'] = gbk2utf8(cutstr($data['author'],$hack_cut_strauthor)); $rthread[$key]['view_lastposter'] = gbk2utf8(cutstr($data['lastposter'],$hack_cut_strauthor)); $rthread[$key]['date']= gmdate("$dateformat $timeformat", $data['dateline'] + $timeoffset * 3600); $rthread[$key]['lastreplytime']= gmdate("$dateformat $timeformat", $data['lastpost'] + ($timeoffset * 3600)); if($data['highlight']) { $string = sprintf('%02d', $data['highlight']); $stylestr = sprintf('%03b', $string[0]); $rthread[$key]['highlight'] = 'style="'; $rthread[$key]['highlight'] .= $stylestr[0] ? 'font-weight: bold;' : ''; $rthread[$key]['highlight'] .= $stylestr[1] ? 'font-style: italic;' : ''; $rthread[$key]['highlight'] .= $stylestr[2] ? 'text-decoration: underline;' : ''; $rthread[$key]['highlight'] .= $string[1] ? 'color: '.$colorarray[$string[1]] : ''; $rthread[$key]['highlight'] .= '"'; } else { $rthread[$key]['highlight'] = ''; } $new_reply_threadlist[] = $rthread; } } } //热帖 $hack_cut_str = 26; //标题字数 $hack_cut_strauthor = 9; $new_hot_threadlist = array(); $mthread = array(); $query ="SELECT t.*, f.name FROM {$dztablepre}threads t, {$dztablepre}forums f WHERE f.fid=t.fid AND t.closed NOT LIKE 'moved|%' AND t.replies !=0 AND f.fid not in (0) AND t.displayorder not in (-1,-2) ORDER BY t.replies DESC LIMIT 0, 10"; if($mthread = $wpdb->get_results($query,ARRAY_A)) { foreach($mthread as $key =>$data) { if($data['tid']) { $mthread[$key]['forumname'] = gbk2utf8(ereg_replace('<[^>]*>','',$data['name'])); $mthread[$key]['view_subject'] =gbk2utf8(cutstr($data['subject'],$hack_cut_str)); $mthread[$key]['subject']=gbk2utf8($data['subject']); $mthread[$key]['author'] =gbk2utf8($data['author']); $mthread[$key]['view_author'] =gbk2utf8(cutstr($data['author'],$hack_cut_strauthor)); $mthread[$key]['view_lastposter'] = gbk2utf8(cutstr($data['lastposter'],$hack_cut_strauthor)); $mthread[$key]['date']= gmdate("$dateformat $timeformat", $data['dateline'] + $timeoffset * 3600); $mthread[$key]['lastreplytime']= gmdate("$dateformat $timeformat", $data['lastpost'] + ($timeoffset * 3600)); if($data['highlight']) { $string = sprintf('%02d', $data['highlight']); $stylestr = sprintf('%03b', $string[0]); $mthread[$key]['highlight'] = 'style="'; $mthread[$key]['highlight'] .= $stylestr[0] ? 'font-weight: bold;' : ''; $mthread[$key]['highlight'] .= $stylestr[1] ? 'font-style: italic;' : ''; $mthread[$key]['highlight'] .= $stylestr[2] ? 'text-decoration: underline;' : ''; $mthread[$key]['highlight'] .= $string[1] ? 'color: '.$colorarray[$string[1]] : ''; $mthread[$key]['highlight'] .= '"'; } else { $mthread[$key]['highlight'] = ''; } $new_hot_threadlist[] = $mthread; } } } //print_r($mthread);die(); //print_r($nthread);die(); ?> <div class="sidebox"> <h2>最新帖子</h2> <ul> <?php foreach($nthread as $key =>$data) { echo "<li><a href=\"{$bbsURL}viewthread.php?tid={$data['tid']} {$data['highlight']}\" target=\"_blank\" title=\"最新帖子 所在论坛: {$data['forumname']} 主题标题: {$data['subject']} ~By {$data['view_author']} 发表时间: {$data['date']} 浏览次数: {$data['views']}次\"; >{$data['view_subject']}</a></li>"; } ?> </ul> </div> <div class="sidebox"> <h2>最新回复</h2> <ul> <?php foreach($rthread as $key =>$data) { echo "<li><a href=\"{$bbsURL}viewthread.php?tid={$data['tid']} {$data['highlight']}\" target=\"_blank\" title=\"帖子 所在论坛: {$data['forumname']} 主题标题: {$data['subject']} ~By {$data['view_author']} 发表时间: {$data['date']} 浏览次数: {$data['views']}次 由[{$data['view_lastposter']}]于{$data['lastreplytime']} 最后回复\"; >{$data['view_subject']}</a></li>"; } ?> </ul> </div> <div class="sidebox"> <h2>热门帖子</h2> <ul> <?php foreach($mthread as $key =>$data) { echo "<li><a href=\"{$bbsURL}viewthread.php?tid={$data['tid']} {$data['highlight']}\" target=\"_blank\" title=\"最新帖子 所在论坛: {$data['forumname']} 主题标题: {$data['subject']} ~By {$data['view_author']} 发表时间: {$data['date']} 浏览次数: {$data['views']}次 由[{$data['view_lastposter']}]于{$data['lastreplytime']} 最后回复\"; >{$data['view_subject']}</a></li>"; } ?> </ul> </div> <div class="clear"></div> </div> <div id="sidebar_bottom"></div> </div> |
截个图吧:
3 Responses
Post a comment







第一个功能现在通过wp3以上的自定义菜单就可以实现了吧
嗯,是的,我这篇文章N久以前发表的,你看下发表日期就知道了。
CMS的主题我不会用。支持一下。吼~~