{"id":30743,"date":"2024-11-25T12:16:33","date_gmt":"2024-11-25T04:16:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/30743\/"},"modified":"2024-11-25T12:16:33","modified_gmt":"2024-11-25T04:16:33","slug":"%e5%a6%82%e4%bd%95%e8%87%aa%e5%8a%a8%e4%b8%bawordpress%e6%96%87%e7%ab%a0%e6%b7%bb%e5%8a%a0%e7%89%b9%e8%89%b2%e5%9b%be%e5%83%8f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/30743\/","title":{"rendered":"\u5982\u4f55\u81ea\u52a8\u4e3aWordPress\u6587\u7ae0\u6dfb\u52a0\u7279\u8272\u56fe\u50cf"},"content":{"rendered":"<p>\u4e0b\u9762\u7531\/&#8221; target=&#8221;_blank&#8221;&gt;<strong>wordpress\u6559\u7a0b<\/strong>\u680f\u76ee\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u81ea\u52a8\u4e3awordpress\u6587\u7ae0\u6dfb\u52a0\u7279\u8272\u56fe\u50cf\u7684\u65b9\u6cd5\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p style=\"text-align: center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/020\/5e06cfcd0c610884.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u81ea\u52a8\u4e3aWordPress\u6587\u7ae0\u6dfb\u52a0\u7279\u8272\u56fe\u50cf\u63d2\u56fe\" alt=\"\u5982\u4f55\u81ea\u52a8\u4e3aWordPress\u6587\u7ae0\u6dfb\u52a0\u7279\u8272\u56fe\u50cf\u63d2\u56fe\" \/><\/p>\n<p>WordPress\u7684\u7279\u8272\u56fe\u50cf\u662f\u4e00\u4e2a\u5f88\u5b9e\u7528\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u5728\u6587\u7ae0\u5217\u8868\u4e2d\u4e3a\u6bcf\u7bc7\u6587\u7ae0\u6dfb\u52a0\u4e00\u5f20\u7f29\u7565\u56fe\u3002\u4f46\u7279\u8272\u56fe\u50cf\u9700\u8981\u5728\u7f16\u8f91\u6587\u7ae0\u65f6\u624b\u52a8\u6dfb\u52a0\u5f88\u4e0d\u65b9\u4fbf\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u53ef\u81ea\u52a8\u5c06\u6587\u7ae0\u4e2d\u7684\u7b2c\u4e00\u5f20\u56fe\u7247\u8bbe\u7f6e\u4e3a\u7279\u8272\u56fe\u50cf\u3002<\/p>\n<p>\u5c06\u4e0b\u9762\u7684\u4ee3\u7801\u6dfb\u52a0\u5230\u5f53\u524d\u4e3b\u9898\u7684functions.php\u4e2d\uff1a<\/p>\n<pre>function&nbsp;wpforce_featured()&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;global&nbsp;$post;\n&nbsp;&nbsp;&nbsp;&nbsp;$already_has_thumb&nbsp;=&nbsp;has_post_thumbnail($post-&amp;gt;ID);\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!$already_has_thumb)&nbsp;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$attached_image&nbsp;=&nbsp;get_children(&nbsp;\"post_parent=$post-&amp;gt;ID&amp;amp;post_type=attachment&amp;amp;post_mime_type=image&amp;amp;numberposts=1\"&nbsp;);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;($attached_image)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;($attached_image&nbsp;as&nbsp;$attachment_id&nbsp;=&amp;gt;&nbsp;$attachment)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set_post_thumbnail($post-&amp;gt;ID,&nbsp;$attachment_id);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;}\n}&nbsp;&nbsp;\/\/end&nbsp;function\nadd_action('the_post',&nbsp;'wpforce_featured');\nadd_action('save_post',&nbsp;'wpforce_featured');\nadd_action('draft_to_publish',&nbsp;'wpforce_featured');\nadd_action('new_to_publish',&nbsp;'wpforce_featured');\nadd_action('pending_to_publish',&nbsp;'wpforce_featured');\nadd_action('future_to_publish',&nbsp;'wpforce_featured');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5982\u679c\u5f53\u524d\u6587\u7ae0\u4e2d\u6ca1\u6709\u56fe\u7247\uff0c\u4f46\u53c8\u60f3\u663e\u793a\u4e00\u5f20\u9ed8\u8ba4\u7684\u7f29\u7565\u56fe\u8be5\u600e\u4e48\u529e\uff0c\u53ef\u4ee5\u5c06\u4e0a\u9762\u7684\u4ee3\u7801\u4fee\u6539\u4e00\u4e0b\uff0c\u8c03\u7528\u5a92\u4f53\u5e93\u4e2d\u67d0\u4e2a\u56fe\u7247\u4f5c\u4e3a\u9ed8\u8ba4\u7684\u7f29\u7565\u56fe\uff1a<\/p>\n<pre>function&nbsp;wpforce_featured()&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;global&nbsp;$post;\n&nbsp;&nbsp;&nbsp;&nbsp;$already_has_thumb&nbsp;=&nbsp;has_post_thumbnail($post-&amp;gt;ID);\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!$already_has_thumb)&nbsp;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$attached_image&nbsp;=&nbsp;get_children(&nbsp;\"post_parent=$post-&amp;gt;ID&amp;amp;post_type=attachment&amp;amp;post_mime_type=image&amp;amp;numberposts=1\"&nbsp;);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;($attached_image)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;($attached_image&nbsp;as&nbsp;$attachment_id&nbsp;=&amp;gt;&nbsp;$attachment)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set_post_thumbnail($post-&amp;gt;ID,&nbsp;$attachment_id);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set_post_thumbnail($post-&amp;gt;ID,&nbsp;'414');\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;}\n}&nbsp;&nbsp;\/\/end&nbsp;function\nadd_action('the_post',&nbsp;'wpforce_featured');\nadd_action('save_post',&nbsp;'wpforce_featured');\nadd_action('draft_to_publish',&nbsp;'wpforce_featured');\nadd_action('new_to_publish',&nbsp;'wpforce_featured');\nadd_action('pending_to_publish',&nbsp;'wpforce_featured');\nadd_action('future_to_publish',&nbsp;'wpforce_featured');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\u7684\u6570\u5b57414\uff0c\u662f\u5a92\u4f53\u5e93\u4e2d\u67d0\u4e2a\u56fe\u7247\u9644\u4ef6\u7684ID\u53f7\u3002<\/p>\n<p><strong>\u63d0\u793a<\/strong><\/p>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u53ea\u662f\u4e00\u7bc7\u6280\u672f\u6587\u7ae0\uff0c\u53ef\u80fd\u4f1a\u5f71\u54cd\u5230\u4e4b\u524d\u6dfb\u52a0\u7684\u7279\u8272\u56fe\u50cf\uff0c\u6240\u4ee5\u4e0d\u8981\u8f7b\u6613\u5728\u81ea\u5df1\u7684\u7f51\u7ad9\u4e0a\u505a\u8bd5\u9a8c\u3002<\/p>\n<p>\u7279\u8272\u56fe\u50cf\u53ea\u9002\u5408\u4e0d\u5728\u4e4e\u7a7a\u95f4\u6d41\u91cf\u548c\u5927\u5c0f\u7684\u7528\u6237\u4f7f\u7528\uff0c\u56e0\u4e3a\u6bcf\u5f20\u56fe\u7247\u90fd\u4f1a\u88c1\u526a\u6210\u591a\u5f20\u5927\u5c0f\u4e0d\u540c\u7684\u7f29\u7565\u56fe\u65b9\u4fbf\u5728\u4e0d\u540c\u7684\u4f4d\u7f6e\u8c03\u7528\uff0c\u6700\u4e3b\u8981\u7684\u662f\u4e0d\u652f\u6301\u5916\u94fe\uff0c\u5f88\u6d6a\u8d39\u7a7a\u95f4&#8230;.<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u81ea\u52a8\u4e3aWordPress\u6587\u7ae0\u6dfb\u52a0\u7279\u8272\u56fe\u50cf\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u7531\/&#8221; target=&#8221;_blank&#8221;&gt;wordpress\u6559\u7a0b\u680f\u76ee\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u81ea\u52a8\u4e3awordpress\u6587\u7ae0\u6dfb\u52a0\u7279\u8272\u56fe\u50cf\u7684\u65b9\u6cd5\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u6709\u6240\u5e2e\u52a9\uff01 WordPress\u7684\u7279\u8272\u56fe\u50cf\u662f\u4e00\u4e2a\u5f88\u5b9e\u7528\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u5728\u6587\u7ae0\u5217\u8868\u4e2d\u4e3a\u6bcf\u7bc7\u6587\u7ae0\u6dfb\u52a0\u4e00\u5f20\u7f29\u7565\u56fe\u3002\u4f46\u7279\u8272\u56fe\u50cf\u9700\u8981\u5728\u7f16\u8f91\u6587\u7ae0\u65f6\u624b\u52a8\u6dfb\u52a0\u5f88\u4e0d\u65b9\u4fbf\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u53ef\u81ea\u52a8\u5c06\u6587\u7ae0\u4e2d\u7684\u7b2c\u4e00\u5f20\u56fe\u7247\u8bbe\u7f6e\u4e3a\u7279\u8272\u56fe\u50cf\u3002 \u5c06\u4e0b\u9762\u7684\u4ee3\u7801\u6dfb\u52a0\u5230\u5f53\u524d\u4e3b\u9898\u7684functions.php\u4e2d\uff1a function&nbsp;wpforce_featured()&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;global&nbsp;$post; &nbsp;&nbsp;&nbsp;&nbsp;$already_has_thumb&nbsp;=&nbsp;has_post_thumbnail($post-&amp;gt;ID); &nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!$already_has_thumb)&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$attached_image&nbsp;=&nbsp;get_children(&nbsp;&#8220;post_parent=$post-&amp;gt;ID&amp;amp;post_type=attachment&amp;amp;post_mime_type=image&amp;amp;numberposts=1&#8221;&nbsp;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;($attached_image)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;($attached_image&nbsp;as&nbsp;$attachment_id&nbsp;=&amp;gt;&nbsp;$attachment)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set_post_thumbnail($post-&amp;gt;ID,&nbsp;$attachment_id); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;} }&nbsp;&nbsp;\/\/end&nbsp;function add_action(&#8216;the_post&#8217;,&nbsp;&#8216;wpforce_featured&#8217;); add_action(&#8216;save_post&#8217;,&nbsp;&#8216;wpforce_featured&#8217;); add_action(&#8216;draft_to_publish&#8217;,&nbsp;&#8216;wpforce_featured&#8217;); add_action(&#8216;new_to_publish&#8217;,&nbsp;&#8216;wpforce_featured&#8217;); add_action(&#8216;pending_to_publish&#8217;,&nbsp;&#8216;wpforce_featured&#8217;); add_action(&#8216;future_to_publish&#8217;,&nbsp;&#8216;wpforce_featured&#8217;); \u767b\u5f55\u540e\u590d\u5236 \u5982\u679c\u5f53\u524d\u6587\u7ae0\u4e2d\u6ca1\u6709\u56fe\u7247\uff0c\u4f46\u53c8\u60f3\u663e\u793a\u4e00\u5f20\u9ed8\u8ba4\u7684\u7f29\u7565\u56fe\u8be5\u600e\u4e48\u529e\uff0c\u53ef\u4ee5\u5c06\u4e0a\u9762\u7684\u4ee3\u7801\u4fee\u6539\u4e00\u4e0b\uff0c\u8c03\u7528\u5a92\u4f53\u5e93\u4e2d\u67d0\u4e2a\u56fe\u7247\u4f5c\u4e3a\u9ed8\u8ba4\u7684\u7f29\u7565\u56fe\uff1a function&nbsp;wpforce_featured()&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;global&nbsp;$post; &nbsp;&nbsp;&nbsp;&nbsp;$already_has_thumb&nbsp;=&nbsp;has_post_thumbnail($post-&amp;gt;ID); &nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!$already_has_thumb)&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$attached_image&nbsp;=&nbsp;get_children(&nbsp;&#8220;post_parent=$post-&amp;gt;ID&amp;amp;post_type=attachment&amp;amp;post_mime_type=image&amp;amp;numberposts=1&#8221;&nbsp;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;($attached_image)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;($attached_image&nbsp;as&nbsp;$attachment_id&nbsp;=&amp;gt;&nbsp;$attachment)&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set_post_thumbnail($post-&amp;gt;ID,&nbsp;$attachment_id); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set_post_thumbnail($post-&amp;gt;ID,&nbsp;&#8216;414&#8217;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;} }&nbsp;&nbsp;\/\/end&nbsp;function add_action(&#8216;the_post&#8217;,&nbsp;&#8216;wpforce_featured&#8217;); add_action(&#8216;save_post&#8217;,&nbsp;&#8216;wpforce_featured&#8217;); add_action(&#8216;draft_to_publish&#8217;,&nbsp;&#8216;wpforce_featured&#8217;); add_action(&#8216;new_to_publish&#8217;,&nbsp;&#8216;wpforce_featured&#8217;); add_action(&#8216;pending_to_publish&#8217;,&nbsp;&#8216;wpforce_featured&#8217;); add_action(&#8216;future_to_publish&#8217;,&nbsp;&#8216;wpforce_featured&#8217;); \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\u7684\u6570\u5b57414\uff0c\u662f\u5a92\u4f53\u5e93\u4e2d\u67d0\u4e2a\u56fe\u7247\u9644\u4ef6\u7684ID\u53f7\u3002 \u63d0\u793a \u4e0a\u9762\u7684\u4ee3\u7801\u53ea\u662f\u4e00\u7bc7\u6280\u672f\u6587\u7ae0\uff0c\u53ef\u80fd\u4f1a\u5f71\u54cd\u5230\u4e4b\u524d\u6dfb\u52a0\u7684\u7279\u8272\u56fe\u50cf\uff0c\u6240\u4ee5\u4e0d\u8981\u8f7b\u6613\u5728\u81ea\u5df1\u7684\u7f51\u7ad9\u4e0a\u505a\u8bd5\u9a8c\u3002 \u7279\u8272\u56fe\u50cf\u53ea\u9002\u5408\u4e0d\u5728\u4e4e\u7a7a\u95f4\u6d41\u91cf\u548c\u5927\u5c0f\u7684\u7528\u6237\u4f7f\u7528\uff0c\u56e0\u4e3a\u6bcf\u5f20\u56fe\u7247\u90fd\u4f1a\u88c1\u526a\u6210\u591a\u5f20\u5927\u5c0f\u4e0d\u540c\u7684\u7f29\u7565\u56fe\u65b9\u4fbf\u5728\u4e0d\u540c\u7684\u4f4d\u7f6e\u8c03\u7528\uff0c\u6700\u4e3b\u8981\u7684\u662f\u4e0d\u652f\u6301\u5916\u94fe\uff0c\u5f88\u6d6a\u8d39\u7a7a\u95f4&#8230;. \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u81ea\u52a8\u4e3aWordPress\u6587\u7ae0\u6dfb\u52a0\u7279\u8272\u56fe\u50cf\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-30743","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/30743","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=30743"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/30743\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=30743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=30743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=30743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}