WordPress Multisite Nginx 的偽靜態(Rewrite)規則

  WordPress是一個注重美學、易用性和網絡標準的個人信息發布平臺。WordPress 雖為免費的開源軟件,但其價值是無法用金錢來衡量。使用WordPress可以搭建功能強大的網絡信息發布平臺,但更多的是應用于個性化的博客。針對博客的應用,WordPress能讓您省卻對后臺技術的擔心,集中精力做好網站的內容。

珂亦網絡科技采用WordPress ,并開啟了多站點功能,裝了Domain Mapping插件來管理子站點。

把下面代碼存為wordpress.conf,然后在域名配置文件(koryi.com.conf)中嵌入(include wordpress.conf)就行了,些規則也適合單用戶WordPress

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
location ^~ /files/ {
    rewrite ^.*/files/(.*) /wp-includes/ms-files.php?file=$1 last;
}

location / {
    server_name_in_redirect off;
    port_in_redirect off;

    if (!-e $request_filename) {
        rewrite ^.+?(/wp-.*) $1 last;
        rewrite ^.+?(/.*\.php)$ $1 last;
        rewrite ^ /index.php last;
    }

    if (!-e $request_filename) {
        return 404;
    }
}

location ^~ /blogs.dir/ {
    internal;
    root /home/www/wordpress/wp-content;
}

WordPress文章ID不連續的解決方法

WordPress 3.1.2文章ID不連續的解決方法:
1.打開wp-config.php文件,在define (‘WPLANG’, ‘zh_CN’);下一行添加代碼

1
2
define('WP_POST_REVISIONS', false);
define('AUTOSAVE_INTERVAL', false);

2.打開wp-admin\post-new.php(第46行)和wp-admin\post.php(第177行)兩個文件,將下面的這段代碼分別注釋或刪除。

1
wp_enqueue_script('autosave');

3.打開wp-admin\includes\post.php文件,找到代碼

1
if ( $create_in_db ) {

在它的前一行添加

1
$create_in_db = false;

添加江陰印刷網主題自定義菜單并支持二級分類

如果你在使用江陰印刷網風格,而且升級到了WordPress3.0,那么你可以看看主題在3.0下首頁的分類名不顯示的解決辦法,而這篇是使主題支持自定義菜單并支持二級分類。

編輯functions.php文件,在 include (TEMPLATEPATH . ‘/settings.php’); 下添加

1
2
3
4
5
6
7
8
9
register_nav_menus( array(
    'primary' => __( 'Primary Navigation', 'cnt1' ),
) );
   
function cnt1_page_menu_args( $args ) {
    $args['show_home'] = true;
    return $args;
}
add_filter( 'wp_page_menu_args', 'cnt1_page_menu_args' );

編輯header.php文件,查找下例代碼
繼續閱讀

替換coolcode代碼高亮插件為wp-syntax

終于把coolcode代碼高亮插件替換為wp-syntax,wp-syntax 使用簡單,顯示方式簡潔,視覺感官利落,對W3C也友好。

首先下載安裝好wp-syntax,激活插件。
進入PHPMYADMIN替換原來coolcode的插件代碼

1
2
UPDATE `wp_posts` SET `post_content` = replace (`post_content`,'<coolcode','<pre');
UPDATE `wp_posts` SET `post_content` = replace (`post_content`,'</coolcode','</pre');

wp-syntax是用以下代碼,設置對應參數來完成 wp-syntax 高亮代碼顯示的,編輯文章時,選擇HTML模式下
<pre lang=”LANGUAGE” line=”1″>要顯示的代碼</pre>
相關參數說明:
lang=”LANGUAGE”,在language處填寫你要運行的代碼語言,如css、php、html、javascript等;
line=”1″,1表示代碼從第一行開始顯示,可以不寫,不寫為全部顯示。

wp-syntax 還支持下面代碼:
abap, actionscript, actionscript3, ada, apache, applescript, aptsources, asm, asp, autoit, avisynth, bash, bf, blitzbasic, bnf, boo, c, cmac, caddcl, cadlisp, cil, cfdg, cfm, cobol, cpp-qt, cpp, csharp, css, d, dcs, delphi, diff, div, dos, dot, eiffel, email, fortran, freebasic, genero, gettext, glsl, gml, bnuplot, groovy, haskell, hq9plus, html4strict, idl, ini, inno, intercal, io, java, java5, javascript, kixtart, klonec, klonecpp, latex, lisp, locobasic, lolcode lotusformulas, lotusscript, lscript, lsl2, lua, m68k, make, matlab, mirc, modula3, mpasm, mxml, mysql, nsis, oberon2, objc, ocaml-brief, ocaml, oobas, oracle11, oracle8, pascal, per, pic16, pixelbender, perl, php-brief, php, plsql, povray, powershell, progress, prolog, providex, python, qbasic, rails, rebol, reg, robots, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, tcl, teraterm, text, thinbasic, tsql, typoscript, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, winbatch, xml, xorg_conf, xpp, z80

如果你嫌每次都要切換到HTML模式,手工添加麻煩的話,你還可以利用WP-Syntax Button插件添加按鈕到編輯框中。

解決江陰印刷網風格適應WordPress3.0

如果你正在使用江陰印刷網風格,而且升級到了WordPress3.0,會出現首頁的分類名不顯示,搜索了一下官方,找到了解決辦法:

編輯主題的index.php文件,找到

1
$wp_query->is_category = false;

改為

1
$wp_query->is_category = true;

再找

1
<?php single_cat_title(); ?>

改為

1
<?php printf( __('%s','ctn1'), single_cat_title('', false)); ?>

這樣就可以正確顯示分類名,如果還有其它問題,可以留言解決。

WordPress主題的jQuery應用之TAB切換效果

首先在header.php的head標簽中加載jQuery庫

1
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>

新建一個JS文件,在header.php的head標簽中加載,JS文件中加入下例代碼:

1
2
3
4
5
6
7
8
9
$(document).ready(function(){
$(".entry-foot span:first").addClass("current");  // 為第一個span添加 .current 的樣式,默認選中
$(".entry-foot ul:not(:first)").hide();  //ul 不是第一個時隱藏
$(".entry-foot span").mouseover(function(){  // 鼠標移到 span 上時觸發函數
$(".entry-foot span").removeClass("current");  //為第一個 span 移除 .current 樣式
$(this).addClass("current");  //為觸發的 span 添加樣式
$(".entry-foot ul").hide();  // 隱藏 ul
$("."+$(this).attr("id")).fadeIn("slow");  // 這句是核心,class(.) 和觸發 span 的ID 一致的 fadeIn(漸顯)
});});

HTML代碼如下:

1
2
3
4
5
6
7
8
9
<div class="tab">
<p>
<span ID="tab1">tab1</span>
<span ID="tab2">tab2</span>
<span ID="tab3">tab3</span></p>
<ul class="tab1">以 LI 形式呈現的 tab1 的內容</ul>
<ul class="tab2">以 LI 形式呈現的 tab2 的內容</ul>
<ul class="tab3">以 LI 形式呈現的 tab3 的內容</ul>
</div>

添加CSS代碼如下:

1
2
3
4
5
6
7
.entry-foot{background-color:#FAFAFA;margin:5px 8px;padding:5px 10px;}
.entry-foot p span{background-color:#EFEFEF;border:1px solid
#CCCCCC;cursor:pointer;margin-right:6px;padding:2px 5px;}
.entry-foot p span.current{background-color:#FAFAFA; border-bottom-color:#fafafa;}
.entry-foot p{border-bottom:1px solid #CCCCCC;font-weight:bold;padding:0 10px 2px;}
.entry-foot li{border-bottom:1px dotted #CCCCCC;padding-bottom:3px;margin:5px 0;}
.entry-foot .mhot,.entry-foot.allhot{display:none;}

原文:http://www.xiaorsz.com/jquery-realize-tab-switch-effect/

WordPress主題的jQuery應用之幻燈片效果

首先在header.php的head標簽中加載jQuery庫

1
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>

新建一個JS文件,在header.php的head標簽中加載,JS文件中加入下例代碼:

1
2
3
4
5
6
7
8
9
10
11
12
13
function slideSwitch() {
var $current = $("#slideshow div.current");
if ( $current.length == 0 ) $current = $("#slideshow div:last");
var $next = $current.next().length ? $current.next() : $("#slideshow div:first");
$current.addClass('prev');
$next.css({opacity: 0.0}).addClass("current").animate({opacity: 1.0}, 1000, function() {
$current.removeClass("current prev");
});
} $(function() {
$("#slideshow span").css("opacity","0.7");
$(".current").css("opacity","1.0");
setInterval( "slideSwitch()", 3000 );
});

HTML代碼如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<div ID="slideshow">
    <div class="current">
        <a href="http://www.jssanhong.com/"><img src="1.jpg" alt="" /></a>
        <span>The First Image</span>
    </div>
    <div>
        <a href="http://www.jssanhong.com/"><img src="2.jpg" alt="" /></a>
        <span>The Second Image</span>
    </div>
    <div>
        <a href="http://www.jssanhong.com/"><img src="3.jpg" alt="" /></a>
        <span>Yes, thd third.</span>
    </div>
</div>

添加CSS代碼如下:

1
2
3
4
5
6
#slideshow{position:relative;height:195px;width:425px;border:10px solid #ddd;margin:0 auto 15px;}
#slideshow div{position:absolute;top:0;left:0;z-index:3;opacity:0.0;height:195px;overflow:hidden;background-color:#FFF;}
#slideshow div.current{z-index:5;}
#slideshow div.prev{z-index:4;}
#slideshow div img{display:block;border:0;margin-bottom:10px;}
#slideshow div span{display:none;position:absolute;bottom:0;left:0;height:50px;line-height:50px;background:#000;color:#fff;width:100%;}

原文:http://www.happinesz.cn/archives/1015/

WordPress主題的jQuery應用之返回頂部滑動效果

首先在header.php的head標簽中加載jQuery庫

1
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>

新建一個JS文件,在header.php的head標簽中加載,JS文件中加入下例代碼:

1
2
$('.top').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);});
$('.bot').click(function(){$('html,body').animate({scrollTop:$('#footer').offset().top}, 800);});

在footer.php文件中加入代碼:

1
2
3
4
<div ID="goto">
    <div class="top">頂端</div>
    <div class="bot">底端</div>
</div>

在CSS文件中添加下例代碼:

1
2
3
4
5
*html #goto { position: absolute; top: expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight/2));}
#goto { position: fixed; left: 50%; top: 50%; bottom: auto; margin-left: -500px; z-index: 999;}
#goto .top, #goto .bot { width: 28px; height: 41px; margin: 5px 0; background-image: url('images/goto.gif'); background-repeat: no-repeat; display: block; text-indent: -9999px; cursor: pointer;}
#goto .top { background-position: 0 0;}
#goto .bot { background-position: 0 100%;}

原文:http://immmmm.com/added-sliding-effect-enhanced.html

WordPress主題的jQuery應用之標題提示

首先在header.php的head標簽中加載jQuery庫

1
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>

新建一個JS文件,在header.php的head標簽中加載,JS文件中加入下例代碼:

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
var sweetTitles = {
    x : 10,                            
    y : 20,                            
    tipElements : "a",                 
    init : function() {
        $(this.tipElements).mouseover(function(e){
            this.myTitle = this.title;
            this.myHref = this.href;
            this.myHref = (this.myHref.length > 30 ? this.myHref.toString().substring(0,30)+"..." : this.myHref);       // url 超過 30 個字符的部分用 ... 代替
            this.title = "";
            var tooltip = "<div id='tooltip'><p>"+this.myTitle+"<em>"+this.myHref+"</em>"+"</p></div>";
            $('body').append(tooltip);
            $('#tooltip')
                .css({
                    "opacity":"0.8",                   // 0.8 為透明度可自行根據喜好調整數字
                    "top":(e.pageY+20)+"px",
                    "left":(e.pageX+10)+"px"
                }).show('fast');   
        }).mouseout(function(){
            this.title = this.myTitle;
            $('#tooltip').remove();
        }).mousemove(function(e){
            $('#tooltip')
            .css({
                "top":(e.pageY+20)+"px",
                "left":(e.pageX+10)+"px"
            });
        });
    }
};
$(function(){
    sweetTitles.init();
});

在CSS文件中添加下例代碼:

1
2
3
body div#tooltip { position:absolute;z-index:1000;max-width:220px;width:auto !important;width:220px;background:#000;text-align:left;padding:5px;min-height:1em;}
body div#tooltip p { margin:0;padding:0;color:#fff;font:12px verdana,arial,sans-serif; }
body div#tooltip p em { display:block;margin-top:3px;color:#f60;font-style:normal;font-weight:bold; }

如果你還用了@回復這樣的jQuery提示效果的話會被標題提示遮掉,可以參照下面解決:
代碼中的tipElements : “a”改成tipElements : “a:not(‘.atreply’)”來排除class為atreply的a標簽,或者用tipElements : “a:not([href^=’#’])”來排除href為錨點的a標簽

原文:http://leeiio.me/sweet-titles-for-jquery/

升級到 WordPress 2.7 了

都升級了幾天了,今天才來寫日志,誰讓wp 2.7dz 7.0正式版的發布日期挨這么近呢,升級完精品收藏,接著就升級精品論壇,總算升級都一切正常。只是WP的主題掛件好像不能拖動了。

空下來,又把朋友的公司WP我的WP合并了,就是用的面向對象(OOP)的使用Wordpress系統 一拖N的用法

空間不大,只能節省一點是一點,而且每次升級WP三個都要升,還有插件,麻煩。其實方法還是蠻實用的,不過就是要注意:每個WP的永久鏈接都要設置成一樣的,而uploads的目錄,后臺要每個設置成不一樣的。

具體代碼是:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
if($_SERVER["HTTP_HOST"]=="www.jssanhong.com" || $_SERVER["HTTP_HOST"]=="koryi.net"){
 
define('DB_NAME', '數據庫名');
define('DB_USER', '用戶名');
define('DB_PASSWORD', '密碼');
define('DB_CHARSET', '');

}else if($_SERVER["HTTP_HOST"]=="www.marcodesign.cn" || $_SERVER["HTTP_HOST"]=="marcodesign.cn"){
 
define('DB_NAME', '數據庫名');
define('DB_USER', '用戶名');
define('DB_PASSWORD', '密碼');
define('DB_CHARSET', 'utf8');

}else if($_SERVER["HTTP_HOST"]=="www.ydcpp.cn" || $_SERVER["HTTP_HOST"]=="ydcpp.cn"){
 
define('DB_NAME', '數據庫名');
define('DB_USER', '用戶名');
define('DB_PASSWORD', '密碼');
define('DB_CHARSET', 'utf8');

}

如果你的define(‘DB_CHARSET’, ‘utf8’); define(‘DB_HOST’, ‘localhost’); define(‘DB_COLLATE’, ”); $table_prefix = ‘wp_’; define (‘WPLANG’, ‘zh_CN’);
都一樣的話,可以放到上面那段代碼的下面,我的由于有個編碼定義了utf8會亂碼,所以加上了編碼設置。