<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>活着 &#187; php</title>
	<atom:link href="http://www.yetlive.com/tags/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.yetlive.com</link>
	<description>活着就好，认真生活每一天</description>
	<lastBuildDate>Fri, 30 Dec 2011 13:17:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>How to Build a Quote Function in WordPress Theme</title>
		<link>http://www.yetlive.com/post/1104.html</link>
		<comments>http://www.yetlive.com/post/1104.html#comments</comments>
		<pubDate>Wed, 20 Jul 2011 02:23:34 +0000</pubDate>
		<dc:creator>认真生活</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.yetlive.com/?p=1104</guid>
		<description><![CDATA[Some times we need to quote others comments in our comment. So theme builder should consider to build this function in comments template. Here I want to share one solution to Build a Quote Function in WordPress Theme. First, we need to custom comment template in functions.php file. Then put this JS code to your [...]]]></description>
			<content:encoded><![CDATA[<p>Some times we need to quote others comments in our comment. So theme builder should consider to build this function in comments template. Here I want to share one solution to Build a Quote Function in <a href="http://www.yetlive.com/tags/wordpress" class="st_tag internal_tag" rel="tag" title="标签 wordpress 下的日志">WordPress</a> Theme.</p>
<p>First, we need to custom comment template in functions.<a href="http://www.yetlive.com/tags/php" class="st_tag internal_tag" rel="tag" title="标签 php 下的日志">php</a> file.</p>
<p>Then put this JS code to your wordpress theme:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1104code3'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11043"><td class="code" id="p1104code3"><pre class="php" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> $<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> document<span style="color: #339933;">.</span>getElementById<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
window<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'RE'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
window<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'RE'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'$'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> $<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> quote<span style="color: #009900;">&#40;</span>authorId<span style="color: #339933;">,</span> commentId<span style="color: #339933;">,</span> commentBodyId<span style="color: #339933;">,</span> commentBox<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> author <span style="color: #339933;">=</span> RE<span style="color: #339933;">.</span>$<span style="color: #009900;">&#40;</span>authorId<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>innerHTML<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">var</span> comment <span style="color: #339933;">=</span> RE<span style="color: #339933;">.</span>$<span style="color: #009900;">&#40;</span>commentBodyId<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>innerHTML<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> insertStr <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&amp;lt; blockquote &amp;gt;'</span><span style="color: #339933;">;</span> insertStr <span style="color: #339933;">+=</span> <span style="color: #0000ff;">'\n&amp;lt; strong&amp;gt;&lt;a href=&quot;#'</span> <span style="color: #339933;">+</span> commentId <span style="color: #339933;">+</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">+</span> author<span style="color: #339933;">.</span>replace<span style="color: #009900;">&#40;</span><span style="color: #339933;">/</span>\t<span style="color: #339933;">|</span>\n<span style="color: #339933;">|</span>\r\n<span style="color: #339933;">/</span>g<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">'&lt;/a&gt;:'</span><span style="color: #339933;">;</span> insertStr <span style="color: #339933;">+=</span> comment<span style="color: #339933;">.</span>replace<span style="color: #009900;">&#40;</span><span style="color: #339933;">/</span>\t<span style="color: #339933;">/</span>g<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> insertStr <span style="color: #339933;">+=</span> <span style="color: #0000ff;">'&amp;lt; /blockquote&amp;gt;\n'</span><span style="color: #339933;">;</span>
insertQuote<span style="color: #009900;">&#40;</span>insertStr<span style="color: #339933;">,</span> commentBox<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> insertQuote<span style="color: #009900;">&#40;</span>insertStr<span style="color: #339933;">,</span> commentBox<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>RE<span style="color: #339933;">.</span>$<span style="color: #009900;">&#40;</span>commentBox<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> RE<span style="color: #339933;">.</span>$<span style="color: #009900;">&#40;</span>commentBox<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>type <span style="color: #339933;">==</span> <span style="color: #0000ff;">'textarea'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
field <span style="color: #339933;">=</span> RE<span style="color: #339933;">.</span>$<span style="color: #009900;">&#40;</span>commentBox<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> alert<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;The comment box does not exist!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>document<span style="color: #339933;">.</span>selection<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
field<span style="color: #339933;">.</span>focus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
sel <span style="color: #339933;">=</span> document<span style="color: #339933;">.</span>selection<span style="color: #339933;">.</span>createRange<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
sel<span style="color: #339933;">.</span>text <span style="color: #339933;">=</span> insertStr<span style="color: #339933;">;</span>
field<span style="color: #339933;">.</span>focus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>field<span style="color: #339933;">.</span>selectionStart <span style="color: #339933;">||</span> field<span style="color: #339933;">.</span>selectionStart <span style="color: #339933;">==</span> <span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">var</span> startPos <span style="color: #339933;">=</span> field<span style="color: #339933;">.</span>selectionStart<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">var</span> endPos <span style="color: #339933;">=</span> field<span style="color: #339933;">.</span>selectionEnd<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">var</span> cursorPos <span style="color: #339933;">=</span> startPos<span style="color: #339933;">;</span>
field<span style="color: #339933;">.</span>value <span style="color: #339933;">=</span> field<span style="color: #339933;">.</span>value<span style="color: #339933;">.</span>substring<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> startPos<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> insertStr <span style="color: #339933;">+</span> field<span style="color: #339933;">.</span>value<span style="color: #339933;">.</span>substring<span style="color: #009900;">&#40;</span>endPos<span style="color: #339933;">,</span> field<span style="color: #339933;">.</span>value<span style="color: #339933;">.</span>length<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
cursorPos <span style="color: #339933;">+=</span> insertStr<span style="color: #339933;">.</span>length<span style="color: #339933;">;</span>
field<span style="color: #339933;">.</span>focus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
field<span style="color: #339933;">.</span>selectionStart <span style="color: #339933;">=</span> cursorPos<span style="color: #339933;">;</span>
field<span style="color: #339933;">.</span>selectionEnd <span style="color: #339933;">=</span> cursorPos<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
field<span style="color: #339933;">.</span>value <span style="color: #339933;">+=</span> insertStr<span style="color: #339933;">;</span> field<span style="color: #339933;">.</span>focus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
window<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'RE_CON'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
window<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'RE_CON'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'quote'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> quote<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Then put a quote link in comments template.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1104code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11044"><td class="code" id="p1104code4"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>a onclick<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;RE_CON.quote('commentauthor-&lt;?php comment_ID() ?&gt;', '&lt; ?php echo <span style="color: #006699; font-weight: bold;">$add_below</span>-<span style="color: #006699; font-weight: bold;">$comment-&gt;comment_ID</span> ?&gt;', 'body-&lt;?php comment_ID() ?&gt;', 'comment');&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;javascript:void(0);&quot;</span><span style="color: #339933;">&gt;</span> Quote <span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p><span style="color: #ff0000;">commentauthor-</span> and <span style="color: #ff0000;">body-</span> should be custom according to your template. You can even find some <a href="http://www.litecoupon.com/" target="_blank">discount coupon codes</a> to purchase software.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yetlive.com/post/1104.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Use Mail To Commenter Plugin in Threaded Comments</title>
		<link>http://www.yetlive.com/post/1102.html</link>
		<comments>http://www.yetlive.com/post/1102.html#comments</comments>
		<pubDate>Sun, 17 Jul 2011 01:22:38 +0000</pubDate>
		<dc:creator>认真生活</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.yetlive.com/?p=1102</guid>
		<description><![CDATA[Last post I told you to make wordpress theme support threaded comments. There is a simple idea. Copy the build-in template. But the idea can not work when you installed Mail to Commenter plugin and still want to use it in your threaded comments supported wordpress themes. So how to solve this problem? I&#8217;ll tell you [...]]]></description>
			<content:encoded><![CDATA[<p>Last post I told you to<a href="http://www.yetlive.com/post/1101.html"> make wordpress theme support threaded comments</a>. There is a simple idea. Copy the build-in template. But the idea can not work when you installed Mail to Commenter plugin and still want to use it in your threaded comments supported <a href="http://www.yetlive.com/tags/wordpress" class="st_tag internal_tag" rel="tag" title="标签 wordpress 下的日志">wordpress</a> themes. So how to solve this problem? I&#8217;ll tell you the solution to use <a href="http://wordpress.org/extend/plugins/mailtocommenter/" target="_blank">Mail to Commenter</a> plugin in threaded comments.</p>
<p>In the \wp-includes\comment-template.<a href="http://www.yetlive.com/tags/php" class="st_tag internal_tag" rel="tag" title="标签 php 下的日志">php</a> you will find the code:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1102code10'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p110210"><td class="code" id="p1102code10"><pre class="php" style="font-family:monospace;">onclick<span style="color: #339933;">=</span><span style="color: #0000ff;">'return addComment.moveForm(\&quot;$add_below-$comment-&amp;gt;comment_ID\&quot;, \&quot;$comment-&amp;gt;comment_ID\&quot;, \&quot;$respond_id\&quot;, \&quot;$post-&amp;gt;ID\&quot;)'</span></pre></td></tr></table></div>

<p>So if you want to use start Mail to Commenters function, you should edit this line. But you should remember one point. You need to judge the threaded comments levels deep. Here is the judgement function:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1102code11'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p110211"><td class="code" id="p1102code11"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$max_depth</span></pre></td></tr></table></div>

<p>So I get the idea now. Mail to Commenter plugin will check the comments if there is a @user or @user: in it. If it find one, it will mail to comment author. So we need to add a Javascript on the “Reply” link. Here is the JS code:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1102code12'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p110212"><td class="code" id="p1102code12"><pre class="php" style="font-family:monospace;">RE_CON<span style="color: #339933;">.</span>reply<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;lt; ?php echo $add_below-$comment-&amp;gt;comment_ID ?&amp;gt;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'&amp;lt; ?php echo $comment-&amp;gt;comment_ID ?&amp;gt;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'comment'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Then you should add this JS code to your theme:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1102code13'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p110213"><td class="code" id="p1102code13"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">function</span> $<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">return</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
window<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'RE'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
window<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'RE'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'$'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> $<span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">function</span> reply<span style="color: #009900;">&#40;</span>authorId<span style="color: #339933;">,</span> commentId<span style="color: #339933;">,</span> commentBox<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> author <span style="color: #339933;">=</span> RE.$<span style="color: #009900;">&#40;</span>authorId<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> insertStr <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;a href=&quot;#'</span> <span style="color: #339933;">+</span> commentId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;@'</span><span style="color: #339933;">+</span> author.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\t|\n|\r\n/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">':&lt;/a&gt; <span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #339933;">;</span>
	insertReply<span style="color: #009900;">&#40;</span>insertStr<span style="color: #339933;">,</span> commentBox<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> insertReply<span style="color: #009900;">&#40;</span>insertStr<span style="color: #339933;">,</span> commentBox<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>RE.$<span style="color: #009900;">&#40;</span>commentBox<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> RE.$<span style="color: #009900;">&#40;</span>commentBox<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">type</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'textarea'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		field <span style="color: #339933;">=</span> RE.$<span style="color: #009900;">&#40;</span>commentBox<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;The comment box does not exist!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>field.<span style="color: #660066;">value</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span>insertStr<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;You've already appended this reply!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>field.<span style="color: #660066;">value</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\s|\t|\n/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		field.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> insertStr<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		field.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> field.<span style="color: #660066;">value</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/[\n]*$/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #339933;">+</span> insertStr<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
window<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'RE_CON'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
window<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'RE_CON'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'reply'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> reply<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>After this, we are now able to use Mail to Commenters in our threaded comments. My solution to Use Mail To Commenter Plugin in Threaded Comments is like this:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1102code14'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p110214"><td class="code" id="p1102code14"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> ?php <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mailtocommenter_button'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>comment_reply_link<span style="color: #009900;">&#40;</span><span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'reply_text'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'Reply'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'depth'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$depth</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'max_depth'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'max_depth'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mailtocommenter_button'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #000088;">$depth</span>
    <span style="color: #339933;">&lt;</span>a <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;comment-reply-link&quot;</span> onclick<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;onclick='return addComment.moveForm(' href=&quot;</span> rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nofollow&quot;</span><span style="color: #339933;">&gt;</span>comment_ID<span style="color: #0000ff;">', '</span><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> ?php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$add_below</span><span style="color: #339933;">-</span><span style="color: #000088;">$comment</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>comment_ID ?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #0000ff;">', '</span><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> ?php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$respond_id</span> ?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #0000ff;">', '</span><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> ?php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>ID ?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span><span style="color: #0000ff;">')'</span><span style="color: #339933;">;</span>RE_CON<span style="color: #339933;">.</span>reply<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;lt; ?php echo $add_below-$comment-&amp;gt;comment_ID ?&amp;gt;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'&amp;lt; ?php echo $comment-&amp;gt;comment_ID ?&amp;gt;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'comment'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">&quot;&amp;gt; &amp;lt; ?php _e('Reply'); ?&amp;gt; &lt;/a&gt;
    &amp;lt; ?php } else { ?&amp;gt;
    &lt;a class=&quot;</span>comment<span style="color: #339933;">-</span>reply<span style="color: #339933;">-</span><span style="color: #990000;">link</span><span style="color: #0000ff;">&quot; onclick=&quot;</span>RE_CON<span style="color: #339933;">.</span>reply<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt; ?php echo $add_below-$comment-&gt;comment_ID ?&gt;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'&lt; ?php echo $comment-&gt;comment_ID ?&gt;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'comment'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">&quot; href=&quot;</span>javascript<span style="color: #339933;">:</span>void<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #0000ff;">&quot; rel=&quot;</span>nofollow<span style="color: #0000ff;">&quot;&gt; &amp;lt; ?php _e('Reply'); ?&amp;gt; &lt;/a&gt;
    &lt;!--?php }?--&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.yetlive.com/post/1102.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用WordPress短代码在博客任意部分添加广告</title>
		<link>http://www.yetlive.com/post/970.html</link>
		<comments>http://www.yetlive.com/post/970.html#comments</comments>
		<pubDate>Mon, 03 May 2010 01:26:41 +0000</pubDate>
		<dc:creator>认真生活</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[adsense]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[广告]]></category>

		<guid isPermaLink="false">http://www.yetlive.com/?p=970</guid>
		<description><![CDATA[其实不怎么满意现在文内广告的位置，本来是想通过判断WP中的more标签位置插入广告的，奈何自己总是很懒，加上毕业设计的任务压在头上，也就作罢了，忽然想起WP的短代码功能似乎可以实现此功能，于是翻了翻WordPress Popular Posts的代码，找出了此段代码，这样就可以轻松在博客文章或者WordPress侧栏中任意位置添加Adsense广告了。 代码很简单，把以下的代码加入到主题的functions.php中： function showad() { return &#8217;&#60;div class=”advertise”&#62; //这里放你的Adsense广告代码 &#60;/div&#62;&#8217;; } add_shortcode(&#8216;advertise&#8217;, &#8217;showad&#8217;); 然后在你想要植入Adsense广告的地方添加[advertise]即可。 通过以上简短的代码可以看出，add_shortcode();中第二个参数为需要添加的函数，第一个参数为使用短代码功能是方括号中应当包含的部分，而return ”语句的两个单引号之间可以放任何你想要放的代码，也就是说短代码不光能够控制广告的位置，也可以实现很多其他的功能，比如我现在用到的WordPress Popular Posts插件和Clean Archives Reloaded插件中都应用到了这个功能。]]></description>
			<content:encoded><![CDATA[<p>其实不怎么满意现在文内广告的位置，本来是想通过判断WP中的more标签位置插入广告的，奈何自己总是很懒，加上毕业设计的任务压在头上，也就作罢了，忽然想起WP的短代码功能似乎可以实现此功能，于是翻了翻<a href="http://wordpress.org/extend/plugins/wordpress-popular-posts/" target="_blank">WordPress Popular Posts</a>的代码，找出了此段代码，这样就可以轻松在博客文章或者<a href="http://www.yetlive.com/">WordPress</a>侧栏中任意位置添加Adsense广告了。<span id="more-970"></span></p>
<p>代码很简单，把以下的代码加入到主题的functions.php中：</p>
<blockquote><p>function showad() {<br />
 return &#8217;&lt;div class=”advertise”&gt;<br />
<span style="color: #ff0000;"> //这里放你的Adsense广告代码</span><br />
 &lt;/div&gt;&#8217;;<br />
 }<br />
 add_shortcode(&#8216;advertise&#8217;, &#8217;showad&#8217;);</p>
</blockquote>
<p>然后在你想要植入<a href="http://www.yetlive.com/tags/adsense">Adsense</a>广告的地方添加[advertise]即可。</p>
<p>通过以上简短的代码可以看出，add_shortcode();中第二个参数为需要添加的函数，第一个参数为使用短代码功能是方括号中应当包含的部分，而return ”语句的两个单引号之间可以放任何你想要放的代码，也就是说短代码不光能够控制<a href="http://www.yetlive.com/post/hide-your-adsense.html">广告的位置</a>，也可以实现很多其他的功能，比如我现在用到的<a href="http://wordpress.org/extend/plugins/wordpress-popular-posts/" target="_blank">WordPress Popular Posts</a>插件和<a href="http://wordpress.org/extend/plugins/clean-archives-reloaded/" target="_blank">Clean Archives Reloaded</a>插件中都应用到了这个功能。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yetlive.com/post/970.html/feed</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
		<item>
		<title>如何让WP主题同时支持嵌套评论与邮件回复</title>
		<link>http://www.yetlive.com/post/926.html</link>
		<comments>http://www.yetlive.com/post/926.html#comments</comments>
		<pubDate>Fri, 09 Apr 2010 07:35:13 +0000</pubDate>
		<dc:creator>认真生活</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.yetlive.com/?p=926</guid>
		<description><![CDATA[本着折腾到底不罢休的精神，又给博客做了个手术，这手术做的可不轻松，啃下了WP最艰难的部分。本次修改主要是为了支持嵌套回复，也是为了提高用户体验的一个重大举措吧，其实要纯粹的支持嵌套回复功能倒是简单，然而同时要正常使用ThinkAgain的Mail to Commenter插件来邮件回复的时候，问题就会随之而来了。昨晚折腾到半夜三点，终究是把问题给解决了。关键点在于如何让主题支持嵌套以及如何支持邮件回复。文章末尾有全套代码！ 让WP主题支持嵌套回复 首先要解决的是让主题嵌套回复，WP2.7版本后就支持此功能，这里可以参考mg12的WordPress 嵌套回复一文。最简单的方法是使用Wordpress自带的wp_list_comments()来自动解决，然而由于wp自带的wp_list_comments()代码稍嫌臃肿且无法自定义，这时候就需要在模板的function.php文件中来自定义评论显示方法，并在comments.php 中利用wp_list_comments(&#8216;callback=custom_comments&#8217;)来显示自定义评论。 在自定义的评论显示方法中，只需要添加如下代码即可： View Code PHP &#60; ?php comment_reply_link&#40;array_merge&#40; $args, array&#40;'depth' =&#62; $depth, 'max_depth' =&#62; $args&#91;'max_depth'&#93;&#41;&#41;&#41; ?&#62; 之后在后台设置中允许嵌套回复就可以了。 让回复功能支持Mail to Commenter插件的邮件回复 以上已经介绍了如何让主题支持嵌套回复了，然而以上的方法无法进行自定义，因此也就无法添加邮件回复所需的触发函数，于是我们需要对以上的方法进行适当的修改，通过研究代码，可以看到“回复”的链接实际上有类似这样的代码： View Code PHPonclick=&#34;addComment.moveForm('comment-&#60; ?php comment_ID() ?&#62;','&#60; ?php comment_ID() ?&#62;', 'respond', '&#60; ?php echo $post-&#62;ID; ?&#62;');&#34; 其中的&#8217;comment-< ?php comment_ID() ?>&#8216;会根据主题而不同例如WP自带的评论回复中该项就是&#8217;div-comment-&#8217;。而另外一个&#8217;respond&#8216;可能会根据不同主题不同，没有过多研究，各位可以自己尝试下。www.yetlive.com 也就是说自定义的时候只要修改下此处就好了，其中还要注意到的一个问题就是判断支持几层嵌套，当嵌套层数超出了WP后台设置的深度时则需要做相应处理，研究了WP的comment-template.php代码后，可以得到如下的方法判断是否已经超出嵌套层数： View Code PHP if&#40; $depth&#60;get_option&#40;'thread_comments_depth'&#41;&#41; 有了这些基础之后，就需要再为此回复链接带上邮件回复触发机制，大家知道Mail to Commenter插件会识别回复中是否存在@user [...]]]></description>
			<content:encoded><![CDATA[<p>本着折腾到底不罢休的精神，又给博客做了个手术，这手术做的可不轻松，啃下了WP最艰难的部分。本次修改主要是为了支持嵌套回复，也是为了提高用户体验的一个重大举措吧，其实要纯粹的支持嵌套回复功能倒是简单，然而同时要正常使用<a href="http://www.thinkagain.cn/" target="_blank">ThinkAgain</a>的<a href="http://wordpress.org/extend/plugins/mailtocommenter/" target="_blank">Mail to Commenter</a>插件来邮件回复的时候，问题就会随之而来了。昨晚折腾到半夜三点，终究是把问题给解决了。关键点在于如何让主题支持嵌套以及如何支持邮件回复。<span style="color: #ff0000;"><strong>文章末尾有全套代码</strong>！</span><span id="more-926"></span></p>
<h3>让WP主题支持嵌套回复</h3>
<p>首先要解决的是让主题嵌套回复，WP2.7版本后就支持此功能，这里可以参考mg12的<a href="http://www.neoease.com/wordpress-thread-comments/" target="_blank">WordPress 嵌套回复</a>一文。最简单的方法是使用Wordpress自带的wp_list_comments()来自动解决，然而由于wp自带的wp_list_comments()代码稍嫌臃肿且无法自定义，这时候就需要在模板的function.php文件中来自定义评论显示方法，并在comments.<a href="http://www.yetlive.com/tags/php" class="st_tag internal_tag" rel="tag" title="标签 php 下的日志">php</a> 中利用wp_list_comments(&#8216;callback=custom_comments&#8217;)来显示自定义评论。</p>
<p>在自定义的评论显示方法中，只需要添加如下代码即可：</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p926code21'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p92621"><td class="code" id="p926code21"><pre class="php" style="font-family:monospace;"> <span style="color: #339933;">&lt;</span> ?php comment_reply_link<span style="color: #009900;">&#40;</span><span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'depth'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$depth</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'max_depth'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'max_depth'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>之后在后台设置中允许嵌套回复就可以了。</p>
<h3>让回复功能支持Mail to Commenter插件的邮件回复</h3>
<p>以上已经介绍了如何让主题支持嵌套回复了，然而以上的方法无法进行自定义，因此也就无法添加邮件回复所需的触发函数，于是我们需要对以上的方法进行适当的修改，通过研究代码，<strong>可以看到“回复”的链接实际上有类似这样的代码</strong>：</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p926code22'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p92622"><td class="code" id="p926code22"><pre class="php" style="font-family:monospace;">onclick<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;addComment.moveForm('comment-&lt; ?php comment_ID() ?&gt;','&lt; ?php comment_ID() ?&gt;', 'respond', '&lt; ?php echo <span style="color: #006699; font-weight: bold;">$post-&gt;ID</span>; ?&gt;');&quot;</span></pre></td></tr></table></div>

<p>其中的&#8217;<span style="color: #ff0000;">comment</span>-< ?php comment_ID() ?>&#8216;会根据主题而不同例如WP自带的评论回复中该项就是&#8217;<span style="color: #ff0000;">div-comment</span>-&#8217;。而另外一个&#8217;<span style="color: #ff0000;">respond</span>&#8216;可能会根据不同主题不同，没有过多研究，各位可以自己尝试下。www.yetlive.com</p>
<p>也就是说自定义的时候只要修改下此处就好了，<strong>其中还要注意到的一个问题就是判断支持几层嵌套，当嵌套层数超出了WP后台设置的深度时则需要做相应处理</strong>，研究了WP的comment-template.php代码后，可以得到如下的方法判断是否已经超出嵌套层数：</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p926code23'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p92623"><td class="code" id="p926code23"><pre class="php" style="font-family:monospace;"> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$depth</span><span style="color: #339933;">&lt;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thread_comments_depth'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>有了这些基础之后，就需要再为此回复链接带上邮件回复触发机制，大家知道Mail to Commenter插件会识别回复中是否存在@user 或者@user：来自动回复邮件，那么就需要为链接上加上一点Javascript代码让其有此功能，我研究了inove的JS代码后，借用如下：</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p926code24'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p92624"><td class="code" id="p926code24"><pre class="php" style="font-family:monospace;">RE_CON<span style="color: #339933;">.</span>reply<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'commentauthor-&lt; ?php comment_ID() ?&gt;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'comment-&lt; ?php comment_ID() ?&gt;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'comment'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>然后需要在主题的头部调用外部JS文件，此JS文件中加入如下代码：</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p926code25'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p92625"><td class="code" id="p926code25"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">function</span> $<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">return</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
window<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'RE'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
window<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'RE'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'$'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> $<span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">function</span> reply<span style="color: #009900;">&#40;</span>authorId<span style="color: #339933;">,</span> commentId<span style="color: #339933;">,</span> commentBox<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> author <span style="color: #339933;">=</span> RE.$<span style="color: #009900;">&#40;</span>authorId<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> insertStr <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;a href=&quot;#'</span> <span style="color: #339933;">+</span> commentId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;@'</span><span style="color: #339933;">+</span> author.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\t|\n|\r\n/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">':&lt;/a&gt; <span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #339933;">;</span>
	insertReply<span style="color: #009900;">&#40;</span>insertStr<span style="color: #339933;">,</span> commentBox<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> insertReply<span style="color: #009900;">&#40;</span>insertStr<span style="color: #339933;">,</span> commentBox<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>RE.$<span style="color: #009900;">&#40;</span>commentBox<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> RE.$<span style="color: #009900;">&#40;</span>commentBox<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">type</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'textarea'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		field <span style="color: #339933;">=</span> RE.$<span style="color: #009900;">&#40;</span>commentBox<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;The comment box does not exist!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>field.<span style="color: #660066;">value</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span>insertStr<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;You've already appended this reply!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>field.<span style="color: #660066;">value</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\s|\t|\n/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		field.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> insertStr<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		field.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> field.<span style="color: #660066;">value</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/[\n]*$/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #339933;">+</span> insertStr<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
window<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'RE_CON'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
window<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'RE_CON'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'reply'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> reply<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>之后，我们的嵌套回复于邮件回复功能就可以实现了。<span style="color: #ff0000;">于是我最终的方法就如下了，也是本主题中用到的方法</span>：</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p926code26'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p92626"><td class="code" id="p926code26"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mailtocommenter_button'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>comment_reply_link<span style="color: #009900;">&#40;</span><span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'reply_text'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Reply'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'depth'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$depth</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'max_depth'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'max_depth'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mailtocommenter_button'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$depth</span><span style="color: #339933;">&lt;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thread_comments_depth'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #339933;">&lt;</span>a  rel<span style="color: #339933;">=</span><span style="color: #0000ff;">'nofollow'</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'comment-reply-link'</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;javascript:void(0);&quot;</span> onclick<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;addComment.moveForm('comment-&lt;?php comment_ID() ?&gt;','&lt; ?php comment_ID() ?&gt;', 'respond', '&lt;?php echo <span style="color: #006699; font-weight: bold;">$post-&gt;ID</span>; ?&gt;');RE_CON.reply('commentauthor-&lt; ?php comment_ID() ?&gt;','comment-&lt; ?php comment_ID() ?&gt;','comment'); &quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span> ?php _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Reply'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span> ?php <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #339933;">&lt;</span>a  rel<span style="color: #339933;">=</span><span style="color: #0000ff;">'nofollow'</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'comment-reply-link'</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;javascript:void(0);&quot;</span> onclick<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;RE_CON.reply('commentauthor-&lt; ?php comment_ID() ?&gt;','comment-&lt; ?php comment_ID() ?&gt;','comment'); &quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span> ?php _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Reply'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>其实在本人的修改中添加了对是否存在邮件回复插件的判断，其实如果是自己用的话不判断也可以，为了方便大家的使用才做了这样的处理，<span style="color: #ff0000;">至于说到JS文件，可以自己打开</span><a href="http://www.yetlive.com/wp-content/themes/simpleblue/js/common.js" target="_blank"><span style="color: #ff0000;">http://www.yetlive.com/wp-content/themes/simpleblue/js/common.js</span></a><span style="color: #ff0000;">复制粘贴</span>。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yetlive.com/post/926.html/feed</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>WordPress 一些函数列表</title>
		<link>http://www.yetlive.com/post/757.html</link>
		<comments>http://www.yetlive.com/post/757.html#comments</comments>
		<pubDate>Sun, 29 Nov 2009 02:22:44 +0000</pubDate>
		<dc:creator>认真生活</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.tinydiary.cn/?p=757</guid>
		<description><![CDATA[收集下WP的一些函数列表方便活着在制作主题的时候使用。另外，Inove主题是一个可以参考的主题，能够找到许多的有用函数，功能强大能够帮助自己制作一款同样强大的主题。 bloginfo(),调用博客信息,函数参数有&#8217;name&#8217;(博客标题)、_e(),输出文字到文档，例如_e(?你好?&#62;使用效果为输出“你好”二字，此函数不是必须的，只是在用来创建可以翻译的主题时使用 get_header() WordPress主题系统用来包含header.php文件的函数 include (TEMPLATEPATH.”header.php”)用来包含文件 get_sidebar(),用于显示 wordpress 边栏 get_footer(),用于显示页脚,即footer.php文件 comments_template(),调用评论模板,需要创建comments.php文件 have_posts()判断你的博客是否有日志,举例:&#60;?php if(have_posts()) : ?&#62; the_post()输出日志内容，the_title()输出日志标题,the_permalink()日志链接,the_content()输出博客内容。 使用方法：&#60;?php while(have_posts()) : the_post(); ?&#62;&#60;a href=?&#60;?php the_permalink(); ?&#62;?&#62;&#60;?php the_title(); ?&#62;&#60;/a&#62;&#60;?php endwhile; ?&#62; the_category(),当前日志所在的所有类别。例如&#60;?php the_category(?, ?) ?&#62;，其中“，”用来区别分类别名。显示结果如此：Name of category 1,Name of category 2 the_author()用来输出当前日志作者的名字 comments_popup_link()调用一个弹出的留言窗口。（此功能必须在后台开启弹出留言的功能），如果没有激活， comments_popup_link() 则只是简单的显示留言列表。例如&#60;?php comments_popup_link(?No Comments &#38;#187;?, ?1 Comment&#38;#187;?, ?% Comments &#38;#187;?); ?&#62; No Comments &#38;#187;是在没有留言的时候显示的。1 Comment [...]]]></description>
			<content:encoded><![CDATA[<p>收集下WP的一些函数列表方便<a href="http://www.yetlive.com">活着</a>在制作主题的时候使用。另外，Inove主题是一个可以参考的主题，能够找到许多的有用函数，功能强大能够帮助自己制作一款同样强大的主题。</p>
<p><span id="more-757"></span></p>
<p>bloginfo(),调用博客信息,函数参数有&#8217;name&#8217;(博客标题)、_e(),输出文字到文档，例如_e(?你好?&gt;使用效果为输出“你好”二字，此函数不是必须的，只是在用来创建可以翻译的主题时使用</p>
<p>get_header() WordPress主题系统用来包含header.php文件的函数</p>
<p>include (TEMPLATEPATH.”header.<a href="http://www.yetlive.com/tags/php" class="st_tag internal_tag" rel="tag" title="标签 php 下的日志">php</a>”)用来包含文件</p>
<p>get_sidebar(),用于显示 <a href="http://www.yetlive.com/tags/wordpress" class="st_tag internal_tag" rel="tag" title="标签 wordpress 下的日志">wordpress</a> 边栏</p>
<p>get_footer(),用于显示页脚,即footer.php文件</p>
<p>comments_template(),调用评论模板,需要创建comments.php文件</p>
<p>have_posts()判断你的博客是否有日志,举例:&lt;?php if(have_posts()) : ?&gt;</p>
<p>the_post()输出日志内容，the_title()输出日志标题,the_permalink()日志链接,the_content()输出博客内容。</p>
<p>使用方法：&lt;?php while(have_posts()) : the_post(); ?&gt;&lt;a href=?&lt;?php the_permalink(); ?&gt;?&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;?php endwhile; ?&gt;</p>
<h3><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-weight: normal; color: #2a3845; line-height: 19px;">the_category(),当前日志所在的所有类别。例如&lt;?php the_category(?, ?) ?&gt;，其中“，”用来区别分类别名。显示结果如此：Name of category 1,Name of category 2</span></h3>
<p>the_author()用来输出当前日志作者的名字</p>
<p>comments_popup_link()调用一个弹出的留言窗口。（此功能必须在后台开启弹出留言的功能），如果没有激活，</p>
<p>comments_popup_link() 则只是简单的显示留言列表。例如&lt;?php comments_popup_link(?No Comments &amp;#187;?, ?1 Comment&amp;#187;?, ?% Comments &amp;#187;?); ?&gt;</p>
<p>No Comments &amp;#187;是在没有留言的时候显示的。1 Comment &amp;#187; 是用于当你刚好有1条留言时候。% Comments &amp;187; 是用于当你有多于一条留言的时候。比如：8 Comments 。百分号 % 用来显示数字。&amp;#187; 是用来显示一个双层箭头 ?。单篇日志查看模式下留言链接函数是不起作用的</p>
<p>edit_post_link(),显示日志编辑链接.这个只有当你以管理身份登录的时候（编辑者，Editor登录也可以）才可见.edit_post_link() 有三个参数。第一个是用来确定哪个词你将用在编辑链接的链接标题。第二个参数是用来显示在链接后面的字符。第三个参数是用于显示在编辑链接后面的字符。如:&lt;?php edit_post_link(“Edit”, ” | “, ?); ?&gt;</p>
<p>the_ID()日志ID</p>
<p>wp_list_cats()调用wordpress分类链接列表,有三个参数.如&lt;?php wp_list_cats(“sort_column=name&amp;optioncount=1&amp;hierarchical=0&#8243;); ?&gt;,其中sort_column=name表示把分类按字符顺序排列,optioncount=1表示每个分类下面的日志数,hierarchial=0表示不把子分类放到子列表元素中.</p>
<p>get_calendar(),输出日历</p>
<p>wp_register(),注册</p>
<p>wp_loginout()登陆或退出</p>
<p>wp_meta(),元数据</p>
<p>previous_post_link(),next_post_link()分别显示上一篇与下一篇的链接.如&lt;?php previous_post_link(’&amp;laquo;%link‘) ?&gt;</p>
<p>page.php 模板文件定制函数</p>
<p>link_pages()显示子页面的链接,例如&lt;?php link_pages(?&lt;p&gt;&lt;strong&gt;Pages:&lt;/strong&gt; ?, ?&lt;/p&gt;?, ?number?); ?&gt;</p>
<p>在 page.php 中，在 &lt;?php the_content(); ?&gt; 输入以下代码：</p>
<p>&lt;?php link_pages(?&lt;p&gt;&lt;strong&gt;Pages:&lt;/strong&gt; ?, ?&lt;/p&gt;?, ?number?); ?&gt;</p>
<p>wp_list_pages(),显示页面列表,使用depth参数限制列表的层数.</p>
<p>get_links_list()显示友情链接</p>
<p>wp_get_archives(),用于显示文章归档列表,例如:wp_get_archives(“type=monthly”)</p>
<p>posts_nav_link()调用博客分页,示例:&lt;?php posts_nav_link(“in between”,”before”,”after”); ?&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yetlive.com/post/757.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP连接Mysql数据库代码</title>
		<link>http://www.yetlive.com/post/187.html</link>
		<comments>http://www.yetlive.com/post/187.html#comments</comments>
		<pubDate>Thu, 26 Mar 2009 15:45:29 +0000</pubDate>
		<dc:creator>认真生活</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.d.zhangpeng.info/?p=187</guid>
		<description><![CDATA[PHP连接Mysql数据库使用如下代码: View Code PHP1 resource mysql_connect &#40;&#91;server &#91;, username &#91;, password &#91;,new_link &#91;, client_flags&#93;&#93;&#93;&#93;&#93; &#41; 其中:server: Mysql服务器,可以包括端口号,例如”hostname:port”或者对于localhost使用”:/path/to/socket”. username:Mysql数据库用户账号 password:数据库密码 new_link: 如果用同样的参数第二次调用mysql_connect(),将不会建立新连接,而将返回已经打开的连接标识.(默认情况不会重新建立连接) client_flag:可以是以下常量的组合:MYSQL_CLIENT_COMPRESS、MYSQL_CLIENT_IGNORE_SPACE或MYSQL_CLIENT_INTERACTIVE。分别表示使用压缩的通信协议、允许在函数名后留空格位、允许设置断开连接之前所空闲等候的interactive_timeout时间。 连接实例： View Code PHP1 2 3 4 5 6 7 8 9 10 11 12 &#60;?php $link=mysql_connect&#40;'localhost','root','123456'&#41;;//创建到root数据库的连 if&#40;$link&#41;//如果连接失败 &#123; echo '服务器信息：'.mysql_get_host_info&#40;$link&#41;;//获取服务器信息 &#125; else//数据库连接不成功 &#123; echo '连接失败：'.mysql_error&#40;&#41;; &#125; mysql_close&#40;$link&#41;;//关闭连接 ?&#62; 数据操作: 数据操作使用mysql_fetch_row()函数，应用标准SQL查询语句。例如： View Code [...]]]></description>
			<content:encoded><![CDATA[<p>PHP连接Mysql数据库使用如下代码:</p>
<p><span id="more-187"></span></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p187code30'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p18730"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p187code30"><pre class="php" style="font-family:monospace;">resource <span style="color: #990000;">mysql_connect</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>server <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> username <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> password <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span>new_link <span style="color: #009900;">&#91;</span><span style="color: #339933;">,</span> client_flags<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>其中:server: Mysql服务器,可以包括端口号,例如”hostname:port”或者对于localhost使用”:/path/to/socket”.</p>
<p>username:Mysql数据库用户账号</p>
<p>password:数据库密码</p>
<p>new_link: 如果用同样的参数第二次调用mysql_connect(),将不会建立新连接,而将返回已经打开的连接标识.(默认情况不会重新建立连接)</p>
<p>client_flag:可以是以下常量的组合:MYSQL_CLIENT_COMPRESS、MYSQL_CLIENT_IGNORE_SPACE或MYSQL_CLIENT_INTERACTIVE。分别表示使用压缩的通信协议、允许在函数名后留空格位、允许设置断开连接之前所空闲等候的interactive_timeout时间。</p>
<h3>连接实例：</h3>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p187code31'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p18731"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p187code31"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
 <span style="color: #000088;">$link</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'root'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'123456'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//创建到root数据库的连</span>
 <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #666666; font-style: italic;">//如果连接失败</span>
 <span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'服务器信息：'</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_get_host_info</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//获取服务器信息</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">else</span><span style="color: #666666; font-style: italic;">//数据库连接不成功</span>
 <span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'连接失败：'</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//关闭连接</span>
 <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>数据操作:</h3>
<p>数据操作使用mysql_fetch_row()函数，应用标准SQL查询语句。例如：</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p187code32'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p18732"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p187code32"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
 <span style="color: #000088;">$select</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'root'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'123456'</span><span style="color: #009900;">&#41;</span>
 or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'连接失败：'</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$b</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;select * from shopping&quot;</span><span style="color: #009900;">&#41;</span>
 or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;表shopping不存在&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">//创建数据集</span>
 <span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_fetch_row</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$b</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
 <span style="color: #666666; font-style: italic;">//显示数据</span>
 <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">//继续检索下一条</span>
 <span style="color: #000088;">$row</span><span style="color: #339933;">=</span><span style="color: #990000;">mysql_fetch_row</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$b</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #990000;">Mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$select</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.yetlive.com/post/187.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP创建图像的方法</title>
		<link>http://www.yetlive.com/post/175.html</link>
		<comments>http://www.yetlive.com/post/175.html#comments</comments>
		<pubDate>Sat, 14 Mar 2009 19:06:10 +0000</pubDate>
		<dc:creator>认真生活</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[网页制作]]></category>

		<guid isPermaLink="false">http://www.d.zhangpeng.info/?p=175</guid>
		<description><![CDATA[使用的ASP制作的博客系统,应该要说ASP制作图像方法的,不过现在正在看PHP+MYSQL的书，先把PHP创建图片的方法分享出来吧。此方法可以用于制作验证码图片。 首先要确保你的PHP捆绑了GD2库，也就是图像函数库。要使用GD2库，需要修改php.ini文件，将”extension=php_gd2.dll”选项前的分号去掉。修改后重启Apache服务器才能开始使用。 好了，看段代码吧： View Code PHP&#60; ?php //（1）创建背景图像。建立一幅150*100的图像 $im = @imagecreate&#40;150,100&#41; or die &#40;&#34;没有安装GD图像库&#34;&#41;; //设置背景颜色 $background_color = imagecolorallocate &#40;$im, 255, 255, 255&#41;; //设置字体颜色 $text_color = imagecolorallocate &#40;$im, 233, 24, 91&#41;; //（2）在背景图象上输入文字。将字符串放到图像上 imagestring &#40;$im, 3, 5, 5, &#34;这是个简单示例&#34;, $ text_color&#41;; //（3）输出图像 header &#40;&#34;Content-type: image/png&#34;&#41;; imageepng &#40;$im&#41;; //（4）清除所有资源 imagedestroy &#40;$im&#41;; ?&#62; 以上就是一个简单的示例了，当然也可以使用原有的图像做背景，使用以下三种格式：ImageCreateFromPNG（）、ImageCreateFromJPEG（）、ImageCreateFromGIF（）。 使用方法如下： $im=ImageCreateFromPNG(&#8216;baseimage.PNG&#8217;);]]></description>
			<content:encoded><![CDATA[<p>使用的ASP制作的博客系统,应该要说ASP制作图像方法的,不过现在正在看PHP+MYSQL的书，先把PHP创建图片的方法分享出来吧。此方法可以用于制作验证码图片。</p>
<p><span id="more-175"></span></p>
<p>首先要确保你的PHP捆绑了GD2库，也就是图像函数库。要使用GD2库，需要修改php.ini文件，将”extension=<a href="http://www.yetlive.com/tags/php" class="st_tag internal_tag" rel="tag" title="标签 php 下的日志">php</a>_gd2.dll”选项前的分号去掉。修改后重启<a href="http://www.yetlive.com/category/domain-host" target="_blank">Apache服务器</a>才能开始使用。</p>
<p>好了，看段代码吧：</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p175code34'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p17534"><td class="code" id="p175code34"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
 <span style="color: #666666; font-style: italic;">//（1）创建背景图像。建立一幅150*100的图像</span>
 <span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">imagecreate</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">150</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span>
or <span style="color: #990000;">die</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;没有安装GD图像库&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">//设置背景颜色</span>
 <span style="color: #000088;">$background_color</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">//设置字体颜色</span>
 <span style="color: #000088;">$text_color</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">233</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">24</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">91</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">//（2）在背景图象上输入文字。将字符串放到图像上</span>
 <span style="color: #990000;">imagestring</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;这是个简单示例&quot;</span><span style="color: #339933;">,</span> $ text_color<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">//（3）输出图像</span>
 <span style="color: #990000;">header</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: image/png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 imageepng <span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">//（4）清除所有资源</span>
 <span style="color: #990000;">imagedestroy</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$im</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>以上就是一个简单的示例了，当然也可以使用原有的图像做背景，使用以下三种格式：ImageCreateFromPNG（）、ImageCreateFromJPEG（）、ImageCreateFromGIF（）。<br />
 使用方法如下：</p>
<p>$im=ImageCreateFromPNG(&#8216;baseimage.PNG&#8217;);</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yetlive.com/post/175.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP、ASP与JSP的比较</title>
		<link>http://www.yetlive.com/post/166.html</link>
		<comments>http://www.yetlive.com/post/166.html#comments</comments>
		<pubDate>Sat, 07 Mar 2009 05:19:41 +0000</pubDate>
		<dc:creator>认真生活</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.d.zhangpeng.info/?p=166</guid>
		<description><![CDATA[<p>目前常用的动态网页语言有PHP（Hypertext Preprocessor)、ASP(Active Server Pages)和JSP(Java Server Pages)。下面建简单比较一下三种语言。</p><p>衡量内容&#160;&#160;&#160;PHP&#160;&#160;&#160;ASP&#160;&#160;&#160;JSP</p><p>运行速度&#160;&#160;&#160;较快&#160;&#160;&#160;较快&#160;&#160;&#160;快</p>]]></description>
			<content:encoded><![CDATA[<p>目前常用的动态网页语言有PHP（Hypertext Preprocessor)、<a href="http://www.yetlive.com/tags/asp" class="st_tag internal_tag" rel="tag" title="标签 asp 下的日志">ASP</a>(Active Server Pages)和JSP(Java Server Pages)。下面建简单比较一下三种语言。</p>
<p><span id="more-166"></span></p>
<p>衡量内容   <a href="http://www.yetlive.com/tags/php" class="st_tag internal_tag" rel="tag" title="标签 php 下的日志">PHP</a>   ASP   <a href="http://www.yetlive.com/tags/jsp" class="st_tag internal_tag" rel="tag" title="标签 jsp 下的日志">JSP</a></p>
<p>运行速度   较快   较快   快</p>
<p>运行损耗   较大   较大   较小</p>
<p>难易程度   简单   简单   易掌握</p>
<p>扩展性   较差   较好   好</p>
<p>安全性   好    较差   好</p>
<p>函数支持   多   较少   多</p>
<p>数据库支持   多   多   多</p>
<p>厂商支持   较多   较少   多</p>
<p>对XML支持   支持   不支持   支持</p>
<p>对组件支持   不支持   支持   支持</p>
<p>应用程度   较广   较广   较广</p>
<p>运行平台   Windows/UNIX   Windows   绝大部分平台</p>
<p>以上就是对几种目前流行的动态网页制作语言的一个简单比较，具体选择什么语言学习则看自己选择了。应该来说，活着更倾向与推荐学习JSP，只是相对来说难度是比较大一点的。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yetlive.com/post/166.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

