{"id":33190,"date":"2024-11-25T10:42:15","date_gmt":"2024-11-25T02:42:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/33190\/"},"modified":"2024-11-25T10:42:15","modified_gmt":"2024-11-25T02:42:15","slug":"wordpress%e6%89%80%e6%9c%89%e6%96%87%e7%ab%a0%e6%80%8e%e4%b9%88%e6%98%be%e7%a4%ba","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/33190\/","title":{"rendered":"wordpress\u6240\u6709\u6587\u7ae0\u600e\u4e48\u663e\u793a"},"content":{"rendered":"<blockquote><p>\n  \u5728 wordpress \u4e2d\u663e\u793a\u6240\u6709\u6587\u7ae0\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u9875\u9762\u6a21\u677f\u521b\u5efa\u9875\u9762\uff0c\u6dfb\u52a0\u67e5\u8be2\u6240\u6709\u6587\u7ae0\u7684\u4ee3\u7801\u3002\u5728\u4fa7\u8fb9\u680f\u6dfb\u52a0\u201c\u6700\u65b0\u6587\u7ae0\u201d\u5c0f\u90e8\u4ef6\u3002\u5728\u4e3b\u9898\u7684 functions.php \u6587\u4ef6\u4e2d\u6dfb\u52a0\u67e5\u8be2\u6240\u6709\u6587\u7ae0\u7684 php \u4ee3\u7801\u3002\u5728\u7279\u5b9a\u4f4d\u7f6e\u6dfb\u52a0\u81ea\u5b9a\u4e49\u67e5\u8be2\u7684 php \u4ee3\u7801\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202404\/15\/2024041516481921338.jpg\" class=\"aligncenter\" title=\"wordpress\u6240\u6709\u6587\u7ae0\u600e\u4e48\u663e\u793a\u63d2\u56fe\" alt=\"wordpress\u6240\u6709\u6587\u7ae0\u600e\u4e48\u663e\u793a\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u663e\u793a WordPress \u4e2d\u7684\u6240\u6709\u6587\u7ae0<\/strong><\/p>\n<p>WordPress \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5185\u5bb9\u7ba1\u7406\u7cfb\u7edf\uff0c\u5141\u8bb8\u7528\u6237\u8f7b\u677e\u521b\u5efa\u548c\u7ba1\u7406\u7f51\u7ad9\u3002\u5982\u679c\u60a8\u9700\u8981\u5728\u7f51\u7ad9\u4e0a\u663e\u793a\u6240\u6709\u6587\u7ae0\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u5b9e\u73b0\uff1a<\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a\u4f7f\u7528\u9875\u9762\u6a21\u677f<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u9875\u9762\u6216\u7f16\u8f91\u73b0\u6709\u9875\u9762\u3002<\/li>\n<li>\u5728\u9875\u9762\u7f16\u8f91\u5668\u4e2d\uff0c\u5728\u7f16\u8f91\u533a\u57df\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/li>\n<\/ul>\n<pre>&lt;?php\n\/\/ \u67e5\u8be2\u6240\u6709\u6587\u7ae0\n$args = array(\n    'post_type' =&gt; 'post',\n    'posts_per_page' =&gt; -1,\n);\n$query = new WP_Query( $args );\n\nif ( $query-&gt;have_posts() ) :\n    while ( $query-&gt;have_posts() ) : $query-&gt;the_post();\n        \/\/ \u663e\u793a\u6587\u7ae0\u7684\u5185\u5bb9\n        the_title( '&lt;h2&gt;', '&lt;\/h2&gt;' );\n        the_content();\n    endwhile;\nendif;\n\nwp_reset_postdata();\n?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u4fdd\u5b58\u6216\u66f4\u65b0\u9875\u9762\u3002<\/li>\n<\/ul>\n<p><strong>\u65b9\u6cd5 2\uff1a\u4f7f\u7528\u5c0f\u90e8\u4ef6<\/strong><\/p>\n<ul>\n<li>\u8f6c\u5230\u4eea\u8868\u76d8\u4e2d\u7684\u201c\u5916\u89c2\u201d&gt;\u201c\u5c0f\u90e8\u4ef6\u201d\u3002<\/li>\n<li>\u62d6\u653e\u201c\u6700\u65b0\u6587\u7ae0\u201d\u5c0f\u90e8\u4ef6\u5230\u4fa7\u8fb9\u680f\u6216\u5176\u4ed6\u5c0f\u90e8\u4ef6\u533a\u57df\u3002<\/li>\n<li>\u914d\u7f6e\u5c0f\u90e8\u4ef6\uff0c\u5305\u62ec\u8981\u663e\u793a\u7684\u6587\u7ae0\u6570\u91cf\u548c\u5176\u4ed6\u9009\u9879\u3002<\/li>\n<\/ul>\n<p><strong>\u65b9\u6cd5 3\uff1a\u4f7f\u7528 PHP \u4ee3\u7801<\/strong><\/p>\n<ul>\n<li>\u5728\u4e3b\u9898\u7684 functions.php \u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/li>\n<\/ul>\n<pre>function display_all_posts() {\n    \/\/ \u67e5\u8be2\u6240\u6709\u6587\u7ae0\n    $args = array(\n        'post_type' =&gt; 'post',\n        'posts_per_page' =&gt; -1,\n    );\n    $query = new WP_Query( $args );\n\n    if ( $query-&gt;have_posts() ) :\n        echo '&lt;ul&gt;';\n        while ( $query-&gt;have_posts() ) : $query-&gt;the_post();\n            echo '&lt;li&gt;&lt;a href=\"' . get_permalink() . '\"&gt;' . get_the_title() . '&lt;\/a&gt;&lt;\/li&gt;';\n        endwhile;\n        echo '&lt;\/ul&gt;';\n    endif;\n\n    wp_reset_postdata();\n}\n\nadd_shortcode( 'display_all_posts', 'display_all_posts' );<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u5728\u60a8\u60f3\u8981\u663e\u793a\u6587\u7ae0\u7684\u4f4d\u7f6e\u6dfb\u52a0\u4ee5\u4e0b\u77ed\u4ee3\u7801\uff1a<\/li>\n<\/ul>\n<pre>[display_all_posts]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5 4\uff1a\u4f7f\u7528\u81ea\u5b9a\u4e49\u67e5\u8be2<\/strong><\/p>\n<ul>\n<li>\u5728\u4e3b\u9898\u7684\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/li>\n<\/ul>\n<pre>\/\/ \u67e5\u8be2\u6240\u6709\u6587\u7ae0\n$args = array(\n    'post_type' =&gt; 'post',\n    'posts_per_page' =&gt; -1,\n);\n$query = new WP_Query( $args );\n\n\/\/ \u5faa\u73af\u6587\u7ae0\u5e76\u663e\u793a\u5185\u5bb9\nif ( $query-&gt;have_posts() ) :\n    while ( $query-&gt;have_posts() ) : $query-&gt;the_post();\n        \/\/ \u663e\u793a\u6587\u7ae0\u7684\u5185\u5bb9\n        the_title( '&lt;h2&gt;', '&lt;\/h2&gt;' );\n        the_content();\n    endwhile;\nendif;\n\nwp_reset_postdata();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u60a8\u53ef\u4ee5\u5728\u7f51\u7ad9\u7684\u4efb\u4f55\u5730\u65b9\u63d2\u5165\u6b64\u4ee3\u7801\uff0c\u4f8b\u5982\u7279\u5b9a\u9875\u9762\u3001\u6587\u7ae0\u6216\u4fa7\u8fb9\u680f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6240\u6709\u6587\u7ae0\u600e\u4e48\u663e\u793a\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>\u5728 wordpress \u4e2d\u663e\u793a\u6240\u6709\u6587\u7ae0\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u9875\u9762\u6a21\u677f\u521b\u5efa\u9875\u9762\uff0c\u6dfb\u52a0\u67e5\u8be2\u6240\u6709\u6587\u7ae0\u7684\u4ee3\u7801\u3002\u5728\u4fa7\u8fb9\u680f\u6dfb\u52a0\u201c\u6700\u65b0\u6587\u7ae0\u201d\u5c0f\u90e8\u4ef6\u3002\u5728\u4e3b\u9898\u7684 functions.php \u6587\u4ef6\u4e2d\u6dfb\u52a0\u67e5\u8be2\u6240\u6709\u6587\u7ae0\u7684 php \u4ee3\u7801\u3002\u5728\u7279\u5b9a\u4f4d\u7f6e\u6dfb\u52a0\u81ea\u5b9a\u4e49\u67e5\u8be2\u7684 php \u4ee3\u7801\u3002 \u5982\u4f55\u663e\u793a WordPress \u4e2d\u7684\u6240\u6709\u6587\u7ae0 WordPress \u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5185\u5bb9\u7ba1\u7406\u7cfb\u7edf\uff0c\u5141\u8bb8\u7528\u6237\u8f7b\u677e\u521b\u5efa\u548c\u7ba1\u7406\u7f51\u7ad9\u3002\u5982\u679c\u60a8\u9700\u8981\u5728\u7f51\u7ad9\u4e0a\u663e\u793a\u6240\u6709\u6587\u7ae0\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u5b9e\u73b0\uff1a \u65b9\u6cd5 1\uff1a\u4f7f\u7528\u9875\u9762\u6a21\u677f \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u9875\u9762\u6216\u7f16\u8f91\u73b0\u6709\u9875\u9762\u3002 \u5728\u9875\u9762\u7f16\u8f91\u5668\u4e2d\uff0c\u5728\u7f16\u8f91\u533a\u57df\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a &lt;?php \/\/ \u67e5\u8be2\u6240\u6709\u6587\u7ae0 $args = array( &#8216;post_type&#8217; =&gt; &#8216;post&#8217;, &#8216;posts_per_page&#8217; =&gt; -1, ); $query = new WP_Query( $args ); if ( $query-&gt;have_posts() ) : while ( $query-&gt;have_posts() ) : $query-&gt;the_post(); \/\/ \u663e\u793a\u6587\u7ae0\u7684\u5185\u5bb9 the_title( &#8216;&lt;h2&gt;&#8217;, &#8216;&lt;\/h2&gt;&#8217; ); the_content(); [&hellip;]<\/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-33190","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/33190","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=33190"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/33190\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=33190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=33190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=33190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}