{"id":68964,"date":"2021-11-21T13:15:55","date_gmt":"2021-11-21T05:15:55","guid":{"rendered":"http:\/\/www.xiaoyebailong.com\/?p=68964"},"modified":"2021-11-30T01:17:24","modified_gmt":"2021-11-29T17:17:24","slug":"wordpress%e6%96%87%e7%ab%a0%e6%97%a0%e7%89%b9%e8%89%b2%e5%9b%be%e6%97%b6%e9%9a%8f%e6%9c%ba%e6%98%be%e7%a4%ba%e6%8c%87%e5%ae%9a%e7%9a%84%e5%9b%be%e7%89%87%ef%bc%88%e5%b7%b2%e8%a7%a3%e5%86%b3%ef%bc%89","status":"publish","type":"post","link":"http:\/\/www.xiaoyebailong.com\/index.php\/2021\/11\/21\/68964.htm","title":{"rendered":"wordpress\u6587\u7ae0\u65e0\u7279\u8272\u56fe\u65f6\u968f\u673a\u663e\u793a\u6307\u5b9a\u7684\u56fe\u7247\uff08\u5df2\u89e3\u51b3\uff09"},"content":{"rendered":"\n<p><strong>wordpress\u00a0\u663e\u793a\u56fe\u7247\u7684\u903b\u8f91\u662f<\/strong><\/p>\n\n\n\n<p>1 \u5047\u5982\u6587\u7ae0\u6709\u6307\u5b9a\u7279\u8272\u56fe\u5219\u663e\u793a\u7279\u8272\u56fe\u3002<\/p>\n\n\n\n<p>2 \u5047\u5982\u6ca1\u6709\u6307\u5b9a\u7279\u8272\u56fe\u7247\uff0c\u5219\u4f7f\u7528\u6587\u7ae0\u7684\u7b2c\u4e00\u4e2a\u56fe\u7247\u6765\u4f5c\u4e3a\u7f29\u7565\u56fe\u663e\u793a\u3002<\/p>\n\n\n\n<p>3 \u5047\u5982\u6587\u7ae0\u91cc\u9762\u6ca1\u6709\u56fe\u7247\u3002\u5219\u968f\u673a\u4f7f\u7528\u6307\u5b9a\u7684\u56fe\u7247\u4f5c\u4e3a\u7f29\u7565\u56fe\u6765\u663e\u793a\u3002<\/p>\n\n\n\n<p>\u627e\u5230\u63a7\u5236\u5176\u7f29\u7565\u56fe\u7684\u51fd\u6570\u6587\u4ef6\uff1afunctions-theme.php<\/p>\n\n\n\n<p>\u91cc\u9762\u6709\u4e2a\u4f7f\u7528\u56fe\u7247\u7684\u51fd\u6570\uff1a _get_post_thumbnail \u7a0d\u5fae\u6539\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function _get_post_thumbnail($size = 'thumbnail', $class = 'thumb') {\r\n        if (has_post_thumbnail()) {\r\n        $domsxe = get_the_post_thumbnail();\r\n        $images = $strResult&#91;1];\r\n        foreach($images as $src){\r\n                $r_src = $src;\r\n            break;\r\n        }\r\n        }else{\r\n            $thumblink = get_post_meta($post->ID, 'thumblink', true);\r\n                if( _hui('thumblink_s') &amp;&amp; !empty($thumblink) ){\r\n                        $r_src = $thumblink;\r\n                }\r\n                elseif( _hui('thumb_postfirstimg_s') ){\r\n                        $content = $post->post_content;\r\n                preg_match_all('\/&lt;img.*?(?: |\\\\t|\\\\r|\\\\n)?src=&#91;\\'\"]?(.+?)&#91;\\'\"]?(?:(?: |\\\\t|\\\\r|\\\\n)+.*?)?>\/sim', $content, $strResult, PREG_PATTERN_ORDER);\r\n                $images = $strResult&#91;1];\r\n\r\n                foreach($images as $src){\r\n                        if( _hui('thumb_postfirstimg_lastname') ){\r\n                            $filetype = _get_filetype($src);\r\n                            $src = rtrim($src, '.'.$filetype)._hui('thumb_postfirstimg_lastname').'.'.$filetype;\r\n                        }\r\n\r\n                        $r_src = $src;\r\n                        break;\r\n                }\r\n                }\r\n    }\r\n\r\n        if( $r_src ){\r\n                if( _hui('thumbnail_src') ){\r\n                return sprintf('&lt;img data-src=\"%s\" alt=\"%s\" src=\"%s\" class=\"thumb\">', $r_src, $post->post_title._get_delimiter().get_bloginfo('name'), get_stylesheet_directory_uri().'\/img\/thumbnail.png');\r\n                }else{\r\n                return sprintf('&lt;img src=\"%s\" alt=\"%s\" class=\"thumb\">', $r_src, $post->post_title._get_delimiter().get_bloginfo('name'));\r\n                }\r\n    }else{\r\n        \/\/\u539f\u6765\u7684\u4f7f\u7528\u6307\u5b9a\u4e00\u5f20\u56fe\u7247 \r\n\/\/return sprintf('&lt;img data-thumb=\"default\" src=\"%s\" class=\"thumb\">', get_stylesheet_directory_uri().'\/img\/thumbnail.png');\r\n       \/\/ \u73b0\u5728\u4f7f\u7528\u7684\u3002\u968f\u673a\u4f7f\u7528\u6587\u4ef6\u5939\u91cc\u9762\u7684\u56fe\u7247\r\n        $random = mt_rand(1, 8);\r\n        return sprintf('&lt;img data-thumb=\"default\" src=\"%s\" class=\"thumb\">', get_stylesheet_directory_uri().'\/img\/random\/'.$random.'.png');\r\n    }\r\n}<\/code><\/pre>\n\n\n\n<p>\u5c31\u6539\u4e86\u8fd9\u90e8\u5206\uff0c\u5176\u5b83\u4e0d\u53d8\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u539f\u6765\u7684\u4f7f\u7528\u6307\u5b9a\u4e00\u5f20\u56fe\u7247 \r\n\/\/return sprintf('&lt;img data-thumb=\"default\" src=\"%s\" class=\"thumb\">', get_stylesheet_directory_uri().'\/img\/thumbnail.png');\r\n       \/\/ \u73b0\u5728\u4f7f\u7528\u7684\u3002\u968f\u673a\u4f7f\u7528\u6587\u4ef6\u5939\u91cc\u9762\u7684\u56fe\u7247\r\n        $random = mt_rand(1, 8);\r\n        return sprintf('&lt;img data-thumb=\"default\" src=\"%s\" class=\"thumb\">', get_stylesheet_directory_uri().'\/img\/random\/'.$random.'.png');<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>wordpress\u00a0\u663e\u793a\u56fe\u7247\u7684\u903b\u8f91\u662f 1 \u5047\u5982\u6587\u7ae0\u6709\u6307\u5b9a\u7279\u8272\u56fe\u5219\u663e\u793a\u7279\u8272\u56fe\u3002 2 \u5047\u5982\u6ca1\u6709\u6307\u5b9a\u7279\u8272\u56fe\u7247\uff0c\u5219\u4f7f\u7528\u6587\u7ae0\u7684\u7b2c\u4e00\u4e2a\u56fe\u7247\u6765\u4f5c\u4e3a\u7f29\u7565\u56fe\u663e\u793a\u3002 3 \u5047\u5982\u6587\u7ae0\u91cc\u9762\u6ca1\u6709\u56fe\u7247\u3002\u5219\u968f\u673a\u4f7f\u7528\u6307\u5b9a\u7684\u56fe\u7247\u4f5c\u4e3a\u7f29\u7565\u56fe\u6765\u663e\u793a\u3002 \u627e\u5230\u63a7\u5236\u5176\u7f29\u7565\u56fe\u7684\u51fd\u6570\u6587\u4ef6\uff1a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[47,557,556],"topic":[],"class_list":["post-68964","post","type-post","status-publish","format-standard","hentry","category-technology","tag-wordpress","tag-557","tag-556"],"_links":{"self":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/68964","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/comments?post=68964"}],"version-history":[{"count":1,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/68964\/revisions"}],"predecessor-version":[{"id":68965,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/68964\/revisions\/68965"}],"wp:attachment":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/media?parent=68964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/categories?post=68964"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/tags?post=68964"},{"taxonomy":"topic","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/topic?post=68964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}