{"id":750,"date":"2011-10-28T19:19:15","date_gmt":"2011-10-28T11:19:15","guid":{"rendered":"http:\/\/www.yuewei.net\/750.html"},"modified":"2011-10-28T19:19:15","modified_gmt":"2011-10-28T11:19:15","slug":"typecho%e5%92%8cwordpress%e7%9a%84%e8%87%aa%e5%8a%a8%e6%88%aa%e6%96%ad%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"http:\/\/feeng.com\/blog\/750.html","title":{"rendered":"Typecho\u548cWordPress\u7684\u81ea\u52a8\u622a\u65ad\u4ee3\u7801"},"content":{"rendered":"<p>\u4e4b\u524d\u7528Typecho \u642d\u5efa\u4e86\u4e00\u4e2a\u7ad9\u70b9\uff0c\u4f7f\u7528\u7684\u662f\u201c\u8292\u679c\u201d\u4e3b\u9898\uff0c\u9996\u9875\u8f93\u51fa\u7684\u662f\u201c\u6587\u7ae0\u6807\u9898\u201d\uff0c\u800c\u975e\u5185\u5bb9\uff0c\u6240\u4ee5\u4e5f\u5c31\u6ca1\u6709\u624b\u52a8\u52a0more\u6807\u7b7e\u3002\u540e\u6765\u6362\u4e86\u4e3b\u9898\u4e4b\u540e\uff0c\u60b2\u50ac\u7684\u76f4\u63a5\u5168\u6587\u8f93\u51fa\u4e86\u3002\u5982\u679c\u518d\u4e00\u7bc7\u4e00\u7bc7\u7684\u53bb\u6dfb\u52a0more\u6807\u7b7e\u975e\u5f97\u7d2f\u6b7b\u4e0d\u53ef\u3002\u518d\u8bf4\u624b\u52a8\u52a0more\u6807\u7b7e\u7531\u4e8e\u5b57\u6570\u7684\u63a7\u5236\u95ee\u9898\uff0c\u4f1a\u4f7f\u622a\u65ad\u7684\u6587\u7ae0\u957f\u77ed\u4e0d\u4e00\uff0c\u5f71\u54cd\u6574\u4f53\u7f8e\u89c2\u3002\u4f7f\u7528\u81ea\u52a8\u9636\u6bb5\u4ee3\u7801\u7701\u5374\u4e86\u624b\u5de5\u622a\u65ad\u7684\u70e6\u607c\uff0c\u4e5f\u53ef\u4ee5\u8f93\u51fa\u7684\u6574\u4e2a\u6a21\u677f\u9875\u9762\u6bd4\u8f83\u6574\u9f50\u3002<\/p>\n<p><!--more--><\/p>\n<h3>WordPress\u81ea\u52a8\u622a\u65ad\u4ee3\u7801\u4e00\uff1a<\/h3>\n<div>\n<pre>&lt;?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post-&gt;post_content)), 0, 300,\"<span style=\"color: #8b0000\">...<\/span>\"); ?&gt;<\/pre>\n<\/div>\n<p>\u4f7f\u7528\u65b9\u6cd5\uff1a\u7528\u4e0a\u9762\u7684\u4ee3\u7801\u66ff\u6362\u5f53\u524d\u4e3b\u9898archive.php\u3001index.php\u6a21\u677f\u6587\u4ef6\u4e2d\u7c7b\u4f3c\uff1a&lt;?php the_content(&#8216;Read more&#8230;&#8217;); ?&gt;\u6216&lt;?php the_excerpt(); ?&gt;\u3002\u5176\u4e2d\u6570\u5b57200\u662f\u5b57\u6570\uff0c\u53ef\u4ee5\u81ea\u884c\u8c03\u6574\uff0c\u4f46\u6700\u597d\u4fdd\u6301\u4e3a\u5076\u6570\u3002 <\/p>\n<h3>WordPress\u81ea\u52a8\u622a\u65ad\u4ee3\u7801\u4e8c\uff1a <\/h3>\n<div>\n<pre><span style=\"color: #0000ff\">&lt;?<\/span>php\n\n<span style=\"color: #008000\">\/* Auto-excerpt by winy *\/<\/span>\n<a style=\"color: #0000ff\" href=\"http:\/\/www.php.net\/function\">function<\/a> winyexcerpt($max_char = 200, $more_text = '<span style=\"color: #8b0000\">...<\/span>', $limit_type = '<span style=\"color: #8b0000\">content<\/span>') {\n\n    <a style=\"color: #0000ff\" href=\"http:\/\/www.php.net\/if\">if<\/a> ($limit_type == '<span style=\"color: #8b0000\">title<\/span>') { $text = get_the_title(); }\n    <a style=\"color: #0000ff\" href=\"http:\/\/www.php.net\/else\">else<\/a> { $text = get_the_content(); }\n    $text = apply_filters('<span style=\"color: #8b0000\">the_content<\/span>', $text);\n    $text = <a style=\"color: #ffa500\" href=\"http:\/\/www.php.net\/strip_tags\">strip_tags<\/a>(<a style=\"color: #ffa500\" href=\"http:\/\/www.php.net\/str_replace\">str_replace<\/a>('<span style=\"color: #8b0000\">]]&gt;<\/span>', '<span style=\"color: #8b0000\">]]&gt;<\/span>', $text));\n\t$text = <a style=\"color: #ffa500\" href=\"http:\/\/www.php.net\/trim\">trim<\/a>($text);\n     <a style=\"color: #0000ff\" href=\"http:\/\/www.php.net\/if\">if<\/a> (<a style=\"color: #ffa500\" href=\"http:\/\/www.php.net\/strlen\">strlen<\/a>($text) &gt; $max_char) {\n\t\t $text = <a style=\"color: #ffa500\" href=\"http:\/\/www.php.net\/substr\">substr<\/a>($text, 0, $max_char+1);\n         $text = utf8_conver($text);\n\t\t $text = <a style=\"color: #ffa500\" href=\"http:\/\/www.php.net\/str_replace\">str_replace<\/a>(<a style=\"color: #ffa500\" href=\"http:\/\/www.php.net\/array\">array<\/a>(\"<span style=\"color: #8b0000\">\\r<\/span>\", \"<span style=\"color: #8b0000\">\\n<\/span>\"), '<span style=\"color: #8b0000\"> <\/span>', $text);\n\t\t $text .= $more_text;\n\t\t <a style=\"color: #0000ff\" href=\"http:\/\/www.php.net\/if\">if<\/a> ($limit_type == '<span style=\"color: #8b0000\">content<\/span>'){\n\t\t $text = \"<span style=\"color: #8b0000\">&lt;p&gt;<\/span>\".$text.\"<span style=\"color: #8b0000\">&lt;\/p&gt;<\/span>\";\n         $text .= \"<span style=\"color: #8b0000\">&lt;div class='readmore'&gt;&lt;a href='<\/span>\".get_permalink().\"<span style=\"color: #8b0000\">' title='\u67e5\u770b\u5168\u6587\u70b9\u51fb\u6b64\u5904' rel='nofollow'&gt;\u7ee7\u7eed\u9605\u8bfb&lt;\/a&gt;&lt;\/div&gt;<\/span>\";\n\t\t }\n        <a style=\"color: #0000ff\" href=\"http:\/\/www.php.net\/echo\">echo<\/a> $text;\n    } <a style=\"color: #0000ff\" href=\"http:\/\/www.php.net\/else\">else<\/a> {\n\t\t <a style=\"color: #0000ff\" href=\"http:\/\/www.php.net\/if\">if<\/a> ($limit_type == '<span style=\"color: #8b0000\">content<\/span>'){$text = \"<span style=\"color: #8b0000\">&lt;p&gt;<\/span>\".$text.\"<span style=\"color: #8b0000\">&lt;\/p&gt;<\/span>\";}\n        <a style=\"color: #0000ff\" href=\"http:\/\/www.php.net\/echo\">echo<\/a> $text;\n    }\n}\n\n<a style=\"color: #0000ff\" href=\"http:\/\/www.php.net\/function\">function<\/a> utf8_conver($str) {\n        $len = <a style=\"color: #ffa500\" href=\"http:\/\/www.php.net\/strlen\">strlen<\/a>($str);\n        <a style=\"color: #0000ff\" href=\"http:\/\/www.php.net\/for\">for<\/a> ($i=<a style=\"color: #ffa500\" href=\"http:\/\/www.php.net\/strlen\">strlen<\/a>($str)-1; $i&gt;=0; $i-=1){\n                $hex .= '<span style=\"color: #8b0000\"> <\/span>'.<a style=\"color: #ffa500\" href=\"http:\/\/www.php.net\/ord\">ord<\/a>($str[$i]);\n                $ch = <a style=\"color: #ffa500\" href=\"http:\/\/www.php.net\/ord\">ord<\/a>($str[$i]);\n        <a style=\"color: #0000ff\" href=\"http:\/\/www.php.net\/if\">if<\/a> (($ch &amp; 128)==0) <a style=\"color: #0000ff\" href=\"http:\/\/www.php.net\/return\">return<\/a>(<a style=\"color: #ffa500\" href=\"http:\/\/www.php.net\/substr\">substr<\/a>($str,0,$i));\n                <a style=\"color: #0000ff\" href=\"http:\/\/www.php.net\/if\">if<\/a> (($ch &amp; 192)==192) <a style=\"color: #0000ff\" href=\"http:\/\/www.php.net\/return\">return<\/a>(<a style=\"color: #ffa500\" href=\"http:\/\/www.php.net\/substr\">substr<\/a>($str,0,$i));\n        }\n        <a style=\"color: #0000ff\" href=\"http:\/\/www.php.net\/return\">return<\/a>($str.$hex);\n}<\/pre>\n<\/div>\n<p>\u5728\u4e3b\u9898function.php\u91cc\u9762\u63d2\u5165\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u5728\u4e3b\u9898index.php\u6216\u5176\u5b83\u9700\u8981\u6458\u8981\u8f93\u51fa\u7684\u5730\u65b9\uff0c\u627e\u5230&lt;?php the_title(); ?&gt;\u548c&lt;?php the_content(); ?&gt;\uff0c\u4ee5\u4e0a\u5206\u522b\u7528&lt;?php winyexcerpt(60, &#8216;&#8230;&#8217;, &#8216;title&#8217;); ?&gt;\u548c&lt;?php winyexcerpt(350); ?&gt;\u66ff\u6362\u3002\u622a\u53d6\u5b57\u7b26\u6570\u53ef\u81ea\u884c\u4fee\u6539\uff0c\u540e\u9762\u4e24\u4e2a\u53c2\u6570\u5206\u522b\u662f\u672b\u5c3e\u7701\u7565\u7b26\u53f7\u548c\u622a\u53d6\u7c7b\u522b\uff08\u6807\u9898\u6216\u5185\u5bb9\uff09\u3002\u3010\u4ee3\u7801\u6765\u6e90\uff1a<a title=\"\u5206\u4eab\u4e00\u6bb5wordpress\u81ea\u52a8\u622a\u65ad\u4ee3\u7801\" href=\"http:\/\/winysky.com\/automatically-truncated-to-share-some-code-wordpress\" target=\"_blank\" rel=\"noopener noreferrer\">winysky<\/a>\u3011<\/p>\n<h3>Typecho\u81ea\u52a8\u622a\u65ad\u4ee3\u7801\uff1a<\/h3>\n<div>\n<pre>&lt;p&gt;<span style=\"color: #0000ff\">&lt;?<\/span>php $this-&gt;excerpt(200, '<span style=\"color: #8b0000\">...<\/span>'); <span style=\"color: #0000ff\">?&gt;<\/span><span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">a<\/span> <span style=\"color: #ff0000\">href<\/span>=<span style=\"color: #0000ff\">\"&lt;?php $this-&gt;permalink() ?&gt;\"<\/span> <span style=\"color: #ff0000\">rel<\/span>=<span style=\"color: #0000ff\">\"bookmark\"<\/span> <span style=\"color: #ff0000\">title<\/span>=<span style=\"color: #0000ff\">\"\u8be6\u7ec6\u9605\u8bfb\u5173\u4e8e&lt;?php $this-&gt;title(); ?&gt;\"<\/span><span style=\"color: #0000ff\">&gt;<\/span>\u9605\u8bfb\u5168\u6587...<span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">a<\/span><span style=\"color: #0000ff\">&gt;<\/span><span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">p<\/span><span style=\"color: #0000ff\">&gt;<\/span><\/pre>\n<\/div>\n<p>\u4f7f\u7528\u65b9\u6cd5\uff1a\u5728\u6a21\u7248index.php\u6587\u4ef6\u4e2d\uff0c\u7528\u4e0a\u9762\u7684\u4ee3\u7801\u66ff\u6362\u6389&lt;?php $this-&gt;content(); ?&gt;\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u7528Typecho \u642d\u5efa\u4e86\u4e00\u4e2a\u7ad9\u70b9\uff0c\u4f7f\u7528\u7684\u662f\u201c\u8292\u679c\u201d\u4e3b\u9898\uff0c\u9996\u9875\u8f93\u51fa\u7684\u662f\u201c\u6587\u7ae0\u6807\u9898\u201d\uff0c\u800c\u975e\u5185\u5bb9\uff0c\u6240\u4ee5\u4e5f\u5c31\u6ca1\u6709\u624b\u52a8\u52a0more\u6807\u7b7e\u3002\u540e\u6765\u6362\u4e86\u4e3b\u9898\u4e4b\u540e\uff0c\u60b2\u50ac&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[62,73],"_links":{"self":[{"href":"http:\/\/feeng.com\/blog\/wp-json\/wp\/v2\/posts\/750"}],"collection":[{"href":"http:\/\/feeng.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/feeng.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/feeng.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/feeng.com\/blog\/wp-json\/wp\/v2\/comments?post=750"}],"version-history":[{"count":0,"href":"http:\/\/feeng.com\/blog\/wp-json\/wp\/v2\/posts\/750\/revisions"}],"wp:attachment":[{"href":"http:\/\/feeng.com\/blog\/wp-json\/wp\/v2\/media?parent=750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/feeng.com\/blog\/wp-json\/wp\/v2\/categories?post=750"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/feeng.com\/blog\/wp-json\/wp\/v2\/tags?post=750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}