{"id":4903,"date":"2025-11-21T09:17:17","date_gmt":"2025-11-21T01:17:17","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/bjjc\/4903.html"},"modified":"2025-11-21T10:17:41","modified_gmt":"2025-11-21T02:17:41","slug":"wordpress%e6%96%87%e7%ab%a0%e5%bd%a2%e5%bc%8f%e5%88%86%e7%b1%bb%e5%ae%8c%e6%95%b4%e4%bd%bf%e7%94%a8%e6%95%99%e7%a8%8b","status":"publish","type":"bjjc","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/bjjc\/4903.html","title":{"rendered":"WordPress\u6587\u7ae0\u5f62\u5f0f\u5206\u7c7b\uff08Post Formats\uff09\u7684\u542f\u7528\u548c\u5e94\u7528"},"content":{"rendered":"<p>\u672c\u6587\u4ecb\u7ecd\u5982\u4f55\u5728WordPress\u4e2d\u914d\u7f6e\u3001\u542f\u7528\u548c\u4f7f\u7528\u6587\u7ae0\u5f62\u5f0f\u5206\u7c7b\uff08Post Formats\uff09\uff0c\u4ece\u540e\u53f0\u914d\u7f6e\u5230\u524d\u53f0\u5c55\u793a\u7684\u5168\u6d41\u7a0b\u3002<\/p><h2 class=\"wp-block-heading\">\u7b2c\u4e00\u90e8\u5206\uff1a\u914d\u7f6e\u548c\u542f\u7528\u6587\u7ae0\u5f62\u5f0f<\/h2><h3 class=\"wp-block-heading\">1.1 \u5728\u4e3b\u9898\u4e2d\u542f\u7528\u6587\u7ae0\u5f62\u5f0f\u652f\u6301<\/h3><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728\u4e3b\u9898\u7684functions.php\u6587\u4ef6\u4e2d\u542f\u7528\u6587\u7ae0\u5f62\u5f0f\u652f\u6301\uff1a<\/p><pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ \u5728\u4e3b\u9898\u7684functions.php\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\n\n\/\/ \u542f\u7528\u6587\u7ae0\u5f62\u5f0f\u652f\u6301\nfunction my_theme_setup() {\n    \/\/ \u6dfb\u52a0\u6587\u7ae0\u5f62\u5f0f\u652f\u6301\n    add_theme_support('post-formats', array(\n        'aside',   \/\/ \u65e5\u5fd7\n        'gallery', \/\/ \u76f8\u518c\n        'link',    \/\/ \u94fe\u63a5\n        'image',   \/\/ \u56fe\u50cf\n        'quote',   \/\/ \u5f15\u7528\n        'status',  \/\/ \u72b6\u6001\n        'video',   \/\/ \u89c6\u9891\n        'audio',    \/\/ \u97f3\u9891\n        'chat'     \/\/ \u804a\u5929\n    ));\n}\nadd_action('after_setup_theme', 'my_theme_setup');<\/code><\/pre><h3 class=\"wp-block-heading\">1.2 \u81ea\u5b9a\u4e49\u6587\u7ae0\u5f62\u5f0f\u663e\u793a\u540d\u79f0\uff08\u53ef\u9009\uff09<\/h3><p>\u5982\u679c\u4f60\u5e0c\u671b\u81ea\u5b9a\u4e49\u6587\u7ae0\u5f62\u5f0f\u7684\u663e\u793a\u540d\u79f0\uff0c\u53ef\u4ee5\u6dfb\u52a0\u5982\u4e0b\u793a\u4f8b\u4ee3\u7801\uff1a<\/p><pre class=\"wp-block-code\"><code>\/\/ \u81ea\u5b9a\u4e49\u6587\u7ae0\u5f62\u5f0f\u6807\u7b7e\nfunction custom_post_format_strings($strings) {\n    $strings['standard'] = __('\u6587\u7ae0', 'textdomain'); \/\/ \u5c06\"\u6807\u51c6\"\u6539\u4e3a\"\u6587\u7ae0\"\n    $strings['aside'] = __('\u65e5\u5fd7', 'textdomain');\n    $strings['gallery'] = __('\u76f8\u518c', 'textdomain');\n    return $strings;\n}\nadd_filter('gettext_with_context', 'custom_post_format_strings');<\/code><\/pre><p>\u8fd9\u6bb5\u4ee3\u7801\u7684\u76ee\u7684\u662f<strong>\u81ea\u5b9a\u4e49WordPress\u6587\u7ae0\u5f62\u5f0f\uff08Post Formats\uff09\u5728\u540e\u53f0\u754c\u9762\u4e2d\u7684\u663e\u793a\u540d\u79f0<\/strong>\uff0c\u5c06\u9ed8\u8ba4\u7684\u82f1\u6587\u6807\u7b7e\u66ff\u6362\u4e3a\u66f4\u7b26\u5408\u4e2d\u6587\u7528\u6237\u4e60\u60ef\u7684\u540d\u79f0\u3002<\/p><h4 class=\"wp-block-heading\"><strong>\u51fd\u6570\u5b9a\u4e49<\/strong><\/h4><ul class=\"wp-block-list\">\n<li>\u5b9a\u4e49\u4e00\u4e2a\u540d\u4e3a <code>custom_post_format_strings<\/code> \u7684\u51fd\u6570<\/li>\n\n\n\n<li>\u63a5\u6536\u4e00\u4e2a\u53c2\u6570 <code>$strings<\/code>\uff0c\u8fd9\u662fWordPress\u9ed8\u8ba4\u7684\u6587\u7ae0\u5f62\u5f0f\u6807\u7b7e\u6570\u7ec4<\/li>\n<\/ul><h4 class=\"wp-block-heading\"><strong>\u81ea\u5b9a\u4e49\u6807\u7b7e\u6620\u5c04<\/strong><\/h4><pre class=\"wp-block-code\"><code>$strings['standard'] = __('\u6587\u7ae0', 'textdomain'); \/\/ \u5c06\"\u6807\u51c6\"\u6539\u4e3a\"\u6587\u7ae0\"\n$strings['aside'] = __('\u65e5\u5fd7', 'textdomain');\n$strings['gallery'] = __('\u76f8\u518c', 'textdomain');\nreturn $strings;<\/code><\/pre><h4 class=\"wp-block-heading\"><strong>\u539f\u59cb\u6807\u7b7e\u4e0e\u81ea\u5b9a\u4e49\u6807\u7b7e\u5bf9\u7167\u8868\uff1a<\/strong><\/h4><figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u539f\u59cb\u6807\u7b7e<\/th><th>\u81ea\u5b9a\u4e49\u6807\u7b7e<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>standard<\/code><\/td><td><code>\u6587\u7ae0<\/code><\/td><td>\u5c06\u9ed8\u8ba4\u7684&#8221;\u6807\u51c6&#8221;\u683c\u5f0f\u6539\u4e3a&#8221;\u6587\u7ae0&#8221;<\/td><\/tr><tr><td><code>aside<\/code><\/td><td><code>\u65e5\u5fd7<\/code><\/td><td>\u5c06&#8221;\u65e5\u5fd7\/\u968f\u7b14&#8221;\u683c\u5f0f\u6539\u4e3a&#8221;\u65e5\u5fd7&#8221;<\/td><\/tr><tr><td><code>gallery<\/code><\/td><td><code>\u76f8\u518c<\/code><\/td><td>\u5c06&#8221;\u76f8\u518c&#8221;\u683c\u5f0f\u4fdd\u6301\u4e3a&#8221;\u76f8\u518c&#8221;<\/td><\/tr><\/tbody><\/table><\/figure><h4 class=\"wp-block-heading\"><strong>\u6280\u672f\u7ec6\u8282\uff1a<\/strong><\/h4><ul class=\"wp-block-list\">\n<li><code>__()<\/code> \u662fWordPress\u7684\u7ffb\u8bd1\u51fd\u6570\uff0c\u7528\u4e8e\u56fd\u9645\u5316<\/li>\n\n\n\n<li><code>'textdomain'<\/code> \u5e94\u8be5\u66ff\u6362\u4e3a\u4f60\u4e3b\u9898\u7684\u5b9e\u9645\u6587\u672c\u57df<\/li>\n<\/ul><h4 class=\"wp-block-heading\"><strong>\u6302\u8f7d\u8fc7\u6ee4\u5668<\/strong><\/h4><pre class=\"wp-block-code\"><code>add_filter('gettext_with_context', 'custom_post_format_strings');<\/code><\/pre><ul class=\"wp-block-list\">\n<li>\u5c06\u81ea\u5b9a\u4e49\u51fd\u6570\u6302\u8f7d\u5230 <code>gettext_with_context<\/code> \u8fc7\u6ee4\u5668<\/li>\n\n\n\n<li>\u5f53WordPress\u83b7\u53d6\u5e26\u4e0a\u4e0b\u6587\u7684\u7ffb\u8bd1\u6587\u672c\u65f6\u4f1a\u89e6\u53d1\u6b64\u51fd\u6570<\/li>\n<\/ul><h4 class=\"wp-block-heading\"><strong>\u5b8c\u6574\u6539\u8fdb\u7248\u672c1\uff1a\u5b8c\u6574\u8986\u76d6\u6240\u6709\u6587\u7ae0\u5f62\u5f0f<\/strong><\/h4><pre class=\"wp-block-code\"><code>\/\/ \u5b8c\u6574\u81ea\u5b9a\u4e49\u6240\u6709\u6587\u7ae0\u5f62\u5f0f\u6807\u7b7e\nfunction custom_post_format_strings($translation, $text, $context, $domain) {\n    \/\/ \u53ea\u5904\u7406\u6587\u7ae0\u5f62\u5f0f\u76f8\u5173\u7684\u7ffb\u8bd1\n    if ($context === 'Post format') {\n        $custom_strings = array(\n            'Standard' =&gt; '\u6587\u7ae0',\n            'Aside'    =&gt; '\u65e5\u5fd7',\n            'Gallery'  =&gt; '\u76f8\u518c',\n            'Link'     =&gt; '\u94fe\u63a5',\n            'Image'    =&gt; '\u56fe\u7247',\n            'Quote'    =&gt; '\u5f15\u7528',\n            'Status'   =&gt; '\u72b6\u6001',\n            'Video'    =&gt; '\u89c6\u9891',\n            'Audio'    =&gt; '\u97f3\u9891',\n            'Chat'     =&gt; '\u804a\u5929'\n        );\n\n        if (isset($custom_strings[$text])) {\n            return $custom_strings[$text];\n        }\n    }\n    return $translation;\n}\nadd_filter('gettext_with_context', 'custom_post_format_strings', 10, 4);<\/code><\/pre><h4 class=\"wp-block-heading\"><strong>\u5b8c\u6574\u6539\u8fdb\u7248\u672c2\uff1a\u4f7f\u7528\u66f4\u7cbe\u786e\u7684\u8fc7\u6ee4\u5668<\/strong><\/h4><pre class=\"wp-block-code\"><code>\/\/ \u65b9\u6cd51\uff1a\u4f7f\u7528\u4e13\u95e8\u7684post_format_labels\u8fc7\u6ee4\u5668\uff08\u63a8\u8350\uff09\nfunction custom_post_format_labels($labels) {\n    return array(\n        'standard' =&gt; _x('\u6587\u7ae0', 'Post format', 'your-textdomain'),\n        'aside'    =&gt; _x('\u65e5\u5fd7', 'Post format', 'your-textdomain'),\n        'gallery'  =&gt; _x('\u76f8\u518c', 'Post format', 'your-textdomain'),\n        'link'     =&gt; _x('\u94fe\u63a5', 'Post format', 'your-textdomain'),\n        'image'    =&gt; _x('\u56fe\u7247', 'Post format', 'your-textdomain'),\n        'quote'    =&gt; _x('\u5f15\u7528', 'Post format', 'your-textdomain'),\n        'status'   =&gt; _x('\u72b6\u6001', 'Post format', 'your-textdomain'),\n        'video'    =&gt; _x('\u89c6\u9891', 'Post format', 'your-textdomain'),\n        'audio'    =&gt; _x('\u97f3\u9891', 'Post format', 'your-textdomain'),\n        'chat'     =&gt; _x('\u804a\u5929', 'Post format', 'your-textdomain'),\n    );\n}\nadd_filter('post_format_labels', 'custom_post_format_labels');\n\n\/\/ \u65b9\u6cd52\uff1a\u4f7f\u7528get_post_format_strings\u8fc7\u6ee4\u5668\nfunction custom_post_format_strings($strings) {\n    return array(\n        'standard' =&gt; __('\u6587\u7ae0', 'your-textdomain'),\n        'aside'    =&gt; __('\u65e5\u5fd7', 'your-textdomain'),\n        'gallery'  =&gt; __('\u76f8\u518c', 'your-textdomain'),\n        'link'     =&gt; __('\u94fe\u63a5', 'your-textdomain'),\n        'image'    =&gt; __('\u56fe\u7247', 'your-textdomain'),\n        'quote'    =&gt; __('\u5f15\u7528', 'your-textdomain'),\n        'status'   =&gt; __('\u72b6\u6001', 'your-textdomain'),\n        'video'    =&gt; __('\u89c6\u9891', 'your-textdomain'),\n        'audio'    =&gt; __('\u97f3\u9891', 'your-textdomain'),\n        'chat'     =&gt; __('\u804a\u5929', 'your-textdomain'),\n    );\n}\nadd_filter('get_post_format_strings', 'custom_post_format_strings');<\/code><\/pre><h4 class=\"wp-block-heading\">\u5b9e\u9645\u6548\u679c\u5c55\u793a<\/h4><p>\u4fee\u6539\u524d\uff08\u9ed8\u8ba4\u82f1\u6587\u6807\u7b7e\uff09\uff1a<\/p><pre class=\"wp-block-code\"><code>[ ] Standard   [ ] Aside   [ ] Gallery   [ ] Link\n[ ] Image      [ ] Quote   [ ] Status    [ ] Video\n[ ] Audio      [ ] Chat<\/code><\/pre><p>\u4fee\u6539\u540e\uff08\u81ea\u5b9a\u4e49\u4e2d\u6587\u6807\u7b7e\uff09\uff1a<\/p><pre class=\"wp-block-code\"><code>[ ] \u6587\u7ae0   [ ] \u65e5\u5fd7   [ ] \u76f8\u518c   [ ] \u94fe\u63a5\n[ ] \u56fe\u7247   [ ] \u5f15\u7528   [ ] \u72b6\u6001   [ ] \u89c6\u9891\n[ ] \u97f3\u9891   [ ] \u804a\u5929<\/code><\/pre><h4 class=\"wp-block-heading\">\u4f7f\u7528\u6ce8\u610f\u4e8b\u9879<\/h4><p><strong>\u6587\u672c\u57df\u66ff\u6362<\/strong><\/p><pre class=\"wp-block-code\"><code>\/\/ \u9519\u8bef\uff1a\u4f7f\u7528\u9ed8\u8ba4\u7684textdomain\n$strings['standard'] = __('\u6587\u7ae0', 'textdomain');\n\n\/\/ \u6b63\u786e\uff1a\u4f7f\u7528\u4f60\u4e3b\u9898\u7684\u5b9e\u9645\u6587\u672c\u57df\n$strings['standard'] = __('\u6587\u7ae0', 'my-theme');<\/code><\/pre><p><strong>\u51fd\u6570\u6267\u884c\u65f6\u673a<\/strong><\/p><p>\u786e\u4fdd\u4ee3\u7801\u5728\u4e3b\u9898\u7684 <code>functions.php<\/code> \u6587\u4ef6\u4e2d\uff0c\u5e76\u5728 <code>after_setup_theme<\/code> \u52a8\u4f5c\u4e4b\u540e\u6267\u884c\u3002<\/p><p><strong>\u4e0e\u5176\u4ed6\u8fc7\u6ee4\u5668\u7684\u517c\u5bb9\u6027<\/strong><\/p><p>\u5982\u679c\u6709\u5176\u4ed6\u63d2\u4ef6\u4e5f\u4fee\u6539\u6587\u7ae0\u5f62\u5f0f\u6807\u7b7e\uff0c\u9700\u8981\u6ce8\u610f\u6267\u884c\u4f18\u5148\u7ea7\uff1a<\/p><pre class=\"wp-block-code\"><code>\/\/ \u8bbe\u7f6e\u8f83\u4f4e\u7684\u4f18\u5148\u7ea7\uff0c\u786e\u4fdd\u6700\u540e\u6267\u884c\nadd_filter('get_post_format_strings', 'custom_post_format_strings', 20);<\/code><\/pre><h4 class=\"wp-block-heading\">\u8c03\u8bd5\u6280\u5de7<\/h4><p>\u5982\u679c\u9700\u8981\u786e\u8ba4\u4fee\u6539\u662f\u5426\u751f\u6548\uff0c\u53ef\u4ee5\u6dfb\u52a0\u8c03\u8bd5\u4ee3\u7801\uff1a<\/p><pre class=\"wp-block-code\"><code>function debug_post_format_strings($strings) {\n    error_log(print_r($strings, true)); \/\/ \u5728debug.log\u4e2d\u67e5\u770b\u5f53\u524d\u6807\u7b7e\n    return $strings;\n}\nadd_filter('get_post_format_strings', 'debug_post_format_strings');<\/code><\/pre><h2 class=\"wp-block-heading\">\u7b2c\u4e8c\u90e8\u5206\uff1a\u540e\u53f0\u6587\u7ae0\u7f16\u8f91\u754c\u9762\uff08\u53c2\u8003\uff09<\/h2><h3 class=\"wp-block-heading\">2.1 \u6dfb\u52a0\u6587\u7ae0\u5f62\u5f0f\u9009\u62e9\u6846\u6837\u5f0f<\/h3><p>\u4e3a\u4e86\u8ba9\u6587\u7ae0\u5f62\u5f0f\u9009\u62e9\u66f4\u52a0\u76f4\u89c2\uff0c\u6211\u4eec\u53ef\u4ee5\u6dfb\u52a0\u4e00\u4e9bCSS\u6837\u5f0f\uff1a<\/p><pre class=\"wp-block-code\"><code>\/\/ \u6dfb\u52a0\u540e\u53f0\u6837\u5f0f\nfunction post_formats_admin_style() {\n    echo '&lt;style&gt;\n        .post-format-icon:before {\n            font-family: dashicons;\n            font-size: 20px;\n            vertical-align: middle;\n        }\n        .post-format-icon.format-aside:before { content: \"\\f123\"; }\n        .post-format-icon.format-gallery:before { content: \"\\f161\"; }\n        .post-format-icon.format-link:before { content: \"\\f103\"; }\n        .post-format-icon.format-image:before { content: \"\\f128\"; }\n        .post-format-icon.format-quote:before { content: \"\\f122\"; }\n        .post-format-icon.format-status:before { content: \"\\f130\"; }\n        .post-format-icon.format-video:before { content: \"\\f126\"; }\n        .post-format-icon.format-audio:before { content: \"\\f127\"; }\n        .post-format-icon.format-chat:before { content: \"\\f125\"; }\n    &lt;\/style&gt;';\n}\nadd_action('admin_head', 'post_formats_admin_style');<\/code><\/pre><h2 class=\"wp-block-heading\">\u7b2c\u4e09\u90e8\u5206\uff1a\u524d\u7aef\u5c55\u793a\u5904\u7406<\/h2><h3 class=\"wp-block-heading\">3.1 \u6839\u636e\u6587\u7ae0\u5f62\u5f0f\u663e\u793a\u4e0d\u540c\u5185\u5bb9\u6a21\u677f<\/h3><p>\u5728\u4e3b\u9898\u7684\u6a21\u677f\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u6839\u636e\u6587\u7ae0\u5f62\u5f0f\u663e\u793a\u4e0d\u540c\u7684\u5185\u5bb9\u5e03\u5c40\uff1a<\/p><pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ \u5728\u4e3b\u9898\u7684content.php\u6216\u7c7b\u4f3c\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\n\n\/\/ \u83b7\u53d6\u5f53\u524d\u6587\u7ae0\u7684\u5f62\u5f0f\n$format = get_post_format();\nif (false === $format) {\n    $format = 'standard';\n}\n\n\/\/ \u6839\u636e\u6587\u7ae0\u5f62\u5f0f\u52a0\u8f7d\u4e0d\u540c\u7684\u5185\u5bb9\u6a21\u677f\nswitch($format) {\n    case 'aside':\n        \/\/ \u65e5\u5fd7\u5f62\u5f0f\n        echo '&lt;article class=\"post-format-aside\"&gt;';\n        echo '&lt;div class=\"aside-content\"&gt;';\n        the_content();\n        echo '&lt;\/div&gt;';\n        echo '&lt;footer class=\"post-meta\"&gt;';\n        echo '&lt;span class=\"post-date\"&gt;' . get_the_date() . '&lt;\/span&gt;';\n        echo '&lt;\/footer&gt;';\n        echo '&lt;\/article&gt;';\n        break;\n\n    case 'gallery':\n        \/\/ \u76f8\u518c\u5f62\u5f0f\n        echo '&lt;article class=\"post-format-gallery\"&gt;';\n        echo '&lt;h2 class=\"post-title\"&gt;' . get_the_title() . '&lt;\/h2&gt;';\n\n        \/\/ \u83b7\u53d6\u76f8\u518c\u77ed\u4ee3\u7801\u6216\u56fe\u7247\n        $content = get_the_content();\n        if (has_shortcode($content, 'gallery')) {\n            echo '&lt;div class=\"post-gallery\"&gt;';\n            echo do_shortcode($content);\n            echo '&lt;\/div&gt;';\n        } else {\n            \/\/ \u5982\u679c\u6ca1\u6709\u76f8\u518c\u77ed\u4ee3\u7801\uff0c\u663e\u793a\u7279\u8272\u56fe\u7247\n            if (has_post_thumbnail()) {\n                echo '&lt;div class=\"post-thumbnail\"&gt;';\n                the_post_thumbnail('large');\n                echo '&lt;\/div&gt;';\n            }\n            echo '&lt;div class=\"post-content\"&gt;';\n            the_content();\n            echo '&lt;\/div&gt;';\n        }\n\n        echo '&lt;\/article&gt;';\n        break;\n\n    case 'link':\n        \/\/ \u94fe\u63a5\u5f62\u5f0f\n        echo '&lt;article class=\"post-format-link\"&gt;';\n        $content = get_the_content();\n\n        \/\/ \u63d0\u53d6\u94fe\u63a5\n        preg_match('\/&lt;as[^&gt;]*href=\"([^\"]*)\"[^&gt;]*&gt;(.*)&lt;\/a&gt;\/i', $content, $matches);\n\n        if (!empty($matches)) {\n            echo '&lt;div class=\"link-content\"&gt;';\n            echo '&lt;a href=\"' . esc_url($matches[1]) . '\" class=\"external-link\" target=\"_blank\"&gt;';\n            echo '&lt;span class=\"link-title\"&gt;' . (!empty($matches[2]) ? $matches[2] : get_the_title()) . '&lt;\/span&gt;';\n            echo '&lt;span class=\"link-url\"&gt;' . $matches[1] . '&lt;\/span&gt;';\n            echo '&lt;\/a&gt;';\n            echo '&lt;\/div&gt;';\n        } else {\n            \/\/ \u5982\u679c\u6ca1\u6709\u627e\u5230\u94fe\u63a5\uff0c\u6b63\u5e38\u663e\u793a\u5185\u5bb9\n            echo '&lt;div class=\"post-content\"&gt;';\n            the_content();\n            echo '&lt;\/div&gt;';\n        }\n\n        echo '&lt;\/article&gt;';\n        break;\n\n    case 'image':\n        \/\/ \u56fe\u50cf\u5f62\u5f0f\n        echo '&lt;article class=\"post-format-image\"&gt;';\n\n        if (has_post_thumbnail()) {\n            echo '&lt;div class=\"featured-image\"&gt;';\n            the_post_thumbnail('full');\n            echo '&lt;\/div&gt;';\n        }\n\n        echo '&lt;div class=\"image-caption\"&gt;';\n        the_content();\n        echo '&lt;\/div&gt;';\n\n        echo '&lt;\/article&gt;';\n        break;\n\n    case 'quote':\n        \/\/ \u5f15\u7528\u5f62\u5f0f\n        echo '&lt;article class=\"post-format-quote\"&gt;';\n        echo '&lt;blockquote&gt;';\n        the_content();\n        echo '&lt;cite&gt;' . get_the_title() . '&lt;\/cite&gt;';\n        echo '&lt;\/blockquote&gt;';\n        echo '&lt;\/article&gt;';\n        break;\n\n    case 'video':\n        \/\/ \u89c6\u9891\u5f62\u5f0f\n        echo '&lt;article class=\"post-format-video\"&gt;';\n        echo '&lt;h2 class=\"post-title\"&gt;' . get_the_title() . '&lt;\/h2&gt;';\n\n        $content = get_the_content();\n\n        \/\/ \u5c1d\u8bd5\u63d0\u53d6\u89c6\u9891\n        if (has_shortcode($content, 'video') || has_shortcode($content, 'embed')) {\n            echo '&lt;div class=\"video-container\"&gt;';\n            echo apply_filters('the_content', $content);\n            echo '&lt;\/div&gt;';\n        } else {\n            \/\/ \u5982\u679c\u6ca1\u6709\u89c6\u9891\u77ed\u4ee3\u7801\uff0c\u6b63\u5e38\u663e\u793a\u5185\u5bb9\n            echo '&lt;div class=\"post-content\"&gt;';\n            the_content();\n            echo '&lt;\/div&gt;';\n        }\n\n        echo '&lt;\/article&gt;';\n        break;\n\n    case 'audio':\n        \/\/ \u97f3\u9891\u5f62\u5f0f\n        echo '&lt;article class=\"post-format-audio\"&gt;';\n        echo '&lt;h2 class=\"post-title\"&gt;' . get_the_title() . '&lt;\/h2&gt;';\n\n        $content = get_the_content();\n\n        \/\/ \u5c1d\u8bd5\u63d0\u53d6\u97f3\u9891\n        if (has_shortcode($content, 'audio')) {\n            echo '&lt;div class=\"audio-container\"&gt;';\n            echo apply_filters('the_content', $content);\n            echo '&lt;\/div&gt;';\n        } else {\n            \/\/ \u5982\u679c\u6ca1\u6709\u97f3\u9891\u77ed\u4ee3\u7801\uff0c\u6b63\u5e38\u663e\u793a\u5185\u5bb9\n            echo '&lt;div class=\"post-content\"&gt;';\n            the_content();\n            echo '&lt;\/div&gt;';\n        }\n\n        echo '&lt;\/article&gt;';\n        break;\n\n    default:\n        \/\/ \u6807\u51c6\u6587\u7ae0\u5f62\u5f0f\n        echo '&lt;article class=\"post-format-standard\"&gt;';\n        echo '&lt;h2 class=\"post-title\"&gt;' . get_the_title() . '&lt;\/h2&gt;';\n\n        if (has_post_thumbnail()) {\n            echo '&lt;div class=\"post-thumbnail\"&gt;';\n            the_post_thumbnail('medium');\n            echo '&lt;\/div&gt;';\n        }\n\n        echo '&lt;div class=\"post-content\"&gt;';\n        the_content();\n        echo '&lt;\/div&gt;';\n\n        echo '&lt;\/article&gt;';\n        break;\n}\n?&gt;<\/code><\/pre><h2 class=\"wp-block-heading\">\u7b2c\u56db\u90e8\u5206\uff1a\u9ad8\u7ea7\u529f\u80fd\u6269\u5c55<\/h2><h3 class=\"wp-block-heading\">4.1 \u6587\u7ae0\u5f62\u5f0f\u5b58\u6863\u9875\u9762<\/h3><p>\u4e3a\u6bcf\u79cd\u6587\u7ae0\u5f62\u5f0f\u521b\u5efa\u4e13\u95e8\u7684\u5b58\u6863\u9875\u9762\uff1a<\/p><pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ \u521b\u5efa\u6587\u7ae0\u5f62\u5f0f\u5b58\u6863\u67e5\u8be2\nfunction post_format_archive_query($query) {\n    if (!is_admin() &amp;&amp; $query-&gt;is_main_query() &amp;&amp; is_tax('post_format')) {\n        $query-&gt;set('posts_per_page', 12);\n    }\n}\nadd_action('pre_get_posts', 'post_format_archive_query');\n\n\/\/ \u6dfb\u52a0\u6587\u7ae0\u5f62\u5f0f\u5b58\u6863\u9875\u9762\u6807\u9898\nfunction post_format_archive_title($title) {\n    if (is_tax('post_format')) {\n        $format = get_query_var('post_format');\n        $format_strings = array(\n            'post-format-aside' =&gt; '\u65e5\u5fd7',\n            'post-format-gallery' =&gt; '\u76f8\u518c',\n            'post-format-link' =&gt; '\u94fe\u63a5',\n            'post-format-image' =&gt; '\u56fe\u50cf',\n            'post-format-quote' =&gt; '\u5f15\u7528',\n            'post-format-status' =&gt; '\u72b6\u6001',\n            'post-format-video' =&gt; '\u89c6\u9891',\n            'post-format-audio' =&gt; '\u97f3\u9891',\n            'post-format-chat' =&gt; '\u804a\u5929'\n        );\n\n        if (isset($format_strings[$format])) {\n            $title = $format_strings[$format] . '\u5b58\u6863';\n        }\n    }\n    return $title;\n}\nadd_filter('get_the_archive_title', 'post_format_archive_title');<\/code><\/pre><h3 class=\"wp-block-heading\">4.2 \u6587\u7ae0\u5f62\u5f0f\u5c0f\u5de5\u5177<\/h3><p>\u521b\u5efa\u4e00\u4e2a\u663e\u793a\u7279\u5b9a\u6587\u7ae0\u5f62\u5f0f\u7684\u5c0f\u5de5\u5177\uff1a<\/p><pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ \u6587\u7ae0\u5f62\u5f0f\u5c0f\u5de5\u5177\nclass Post_Formats_Widget extends WP_Widget {\n\n    public function __construct() {\n        parent::__construct(\n            'post_formats_widget',\n            '\u6587\u7ae0\u5f62\u5f0f\u5c0f\u5de5\u5177',\n            array('description' =&gt; '\u663e\u793a\u7279\u5b9a\u6587\u7ae0\u5f62\u5f0f\u7684\u6587\u7ae0')\n        );\n    }\n\n    public function widget($args, $instance) {\n        echo $args['before_widget'];\n\n        $title = !empty($instance['title']) ? $instance['title'] : '\u6700\u65b0\u6587\u7ae0';\n        $format = !empty($instance['format']) ? $instance['format'] : 'post-format-standard';\n        $number = !empty($instance['number']) ? $instance['number'] : 5;\n\n        echo $args['before_title'] . apply_filters('widget_title', $title) . $args['after_title'];\n\n        \/\/ \u67e5\u8be2\u6587\u7ae0\n        $posts = new WP_Query(array(\n            'posts_per_page' =&gt; $number,\n            'tax_query' =&gt; array(\n                array(\n                    'taxonomy' =&gt; 'post_format',\n                    'field' =&gt; 'slug',\n                    'terms' =&gt; array($format)\n                )\n            )\n        ));\n\n        if ($posts-&gt;have_posts()) {\n            echo '&lt;ul&gt;';\n            while ($posts-&gt;have_posts()) {\n                $posts-&gt;the_post();\n                echo '&lt;li&gt;';\n                echo '&lt;a href=\"' . get_permalink() . '\"&gt;' . get_the_title() . '&lt;\/a&gt;';\n                echo '&lt;span class=\"post-date\"&gt;' . get_the_date() . '&lt;\/span&gt;';\n                echo '&lt;\/li&gt;';\n            }\n            echo '&lt;\/ul&gt;';\n            wp_reset_postdata();\n        } else {\n            echo '&lt;p&gt;\u6682\u65e0\u6587\u7ae0&lt;\/p&gt;';\n        }\n\n        echo $args['after_widget'];\n    }\n\n    public function form($instance) {\n        $title = !empty($instance['title']) ? $instance['title'] : '';\n        $format = !empty($instance['format']) ? $instance['format'] : 'post-format-standard';\n        $number = !empty($instance['number']) ? $instance['number'] : 5;\n        ?&gt;\n        &lt;p&gt;\n            &lt;label for=\"&lt;?php echo $this-&gt;get_field_id('title'); ?&gt;\"&gt;\u6807\u9898:&lt;\/label&gt;\n            &lt;input class=\"widefat\" id=\"&lt;?php echo $this-&gt;get_field_id('title'); ?&gt;\" \n                   name=\"&lt;?php echo $this-&gt;get_field_name('title'); ?&gt;\" type=\"text\" \n                   value=\"&lt;?php echo esc_attr($title); ?&gt;\"&gt;\n        &lt;\/p&gt;\n        &lt;p&gt;\n            &lt;label for=\"&lt;?php echo $this-&gt;get_field_id('format'); ?&gt;\"&gt;\u6587\u7ae0\u5f62\u5f0f:&lt;\/label&gt;\n            &lt;select class=\"widefat\" id=\"&lt;?php echo $this-&gt;get_field_id('format'); ?&gt;\" \n                    name=\"&lt;?php echo $this-&gt;get_field_name('format'); ?&gt;\"&gt;\n                &lt;option value=\"post-format-standard\" &lt;?php selected($format, 'post-format-standard'); ?&gt;&gt;\u6807\u51c6&lt;\/option&gt;\n                &lt;option value=\"post-format-aside\" &lt;?php selected($format, 'post-format-aside'); ?&gt;&gt;\u65e5\u5fd7&lt;\/option&gt;\n                &lt;option value=\"post-format-gallery\" &lt;?php selected($format, 'post-format-gallery'); ?&gt;&gt;\u76f8\u518c&lt;\/option&gt;\n                &lt;option value=\"post-format-link\" &lt;?php selected($format, 'post-format-link'); ?&gt;&gt;\u94fe\u63a5&lt;\/option&gt;\n                &lt;option value=\"post-format-image\" &lt;?php selected($format, 'post-format-image'); ?&gt;&gt;\u56fe\u50cf&lt;\/option&gt;\n                &lt;option value=\"post-format-quote\" &lt;?php selected($format, 'post-format-quote'); ?&gt;&gt;\u5f15\u7528&lt;\/option&gt;\n                &lt;option value=\"post-format-video\" &lt;?php selected($format, 'post-format-video'); ?&gt;&gt;\u89c6\u9891&lt;\/option&gt;\n                &lt;option value=\"post-format-audio\" &lt;?php selected($format, 'post-format-audio'); ?&gt;&gt;\u97f3\u9891&lt;\/option&gt;\n            &lt;\/select&gt;\n        &lt;\/p&gt;\n        &lt;p&gt;\n            &lt;label for=\"&lt;?php echo $this-&gt;get_field_id('number'); ?&gt;\"&gt;\u663e\u793a\u6570\u91cf:&lt;\/label&gt;\n            &lt;input class=\"tiny-text\" id=\"&lt;?php echo $this-&gt;get_field_id('number'); ?&gt;\" \n                   name=\"&lt;?php echo $this-&gt;get_field_name('number'); ?&gt;\" type=\"number\" \n                   value=\"&lt;?php echo esc_attr($number); ?&gt;\" min=\"1\" max=\"10\"&gt;\n        &lt;\/p&gt;\n        &lt;?php\n    }\n\n    public function update($new_instance, $old_instance) {\n        $instance = array();\n        $instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : '';\n        $instance['format'] = (!empty($new_instance['format'])) ? strip_tags($new_instance['format']) : '';\n        $instance['number'] = (!empty($new_instance['number'])) ? intval($new_instance['number']) : 5;\n        return $instance;\n    }\n}\n\n\/\/ \u6ce8\u518c\u5c0f\u5de5\u5177\nfunction register_post_formats_widget() {\n    register_widget('Post_Formats_Widget');\n}\nadd_action('widgets_init', 'register_post_formats_widget');\n?&gt;<\/code><\/pre><h2 class=\"wp-block-heading\">\u4f7f\u7528\u8bf4\u660e<\/h2><ol class=\"wp-block-list\">\n<li>\u5c06\u4e0a\u8ff0\u4ee3\u7801\u6dfb\u52a0\u5230\u5f53\u524d\u4e3b\u9898\u7684functions.php\u6587\u4ef6\u4e2d<\/li>\n\n\n\n<li>\u6839\u636e\u9700\u8981\u8c03\u6574CSS\u6837\u5f0f\u4ee5\u9002\u5e94\u4f60\u7684\u4e3b\u9898\u8bbe\u8ba1<\/li>\n\n\n\n<li>\u5728WordPress\u540e\u53f0\u7f16\u8f91\u6587\u7ae0\u65f6\uff0c\u53ef\u4ee5\u5728&#8221;\u6587\u7ae0\u5f62\u5f0f&#8221;\u5143\u6846\u4e2d\u9009\u62e9\u4e0d\u540c\u7684\u5f62\u5f0f<\/li>\n\n\n\n<li>\u524d\u53f0\u5c06\u6839\u636e\u9009\u62e9\u7684\u6587\u7ae0\u5f62\u5f0f\u663e\u793a\u4e0d\u540c\u7684\u5e03\u5c40\u548c\u6837\u5f0f<\/li>\n<\/ol><h2 class=\"wp-block-heading\">\u6ce8\u610f\u4e8b\u9879<\/h2><ul class=\"wp-block-list\">\n<li>\u8bf7\u786e\u4fdd\u4f60\u7684\u4e3b\u9898\u652f\u6301\u6587\u7ae0\u5f62\u5f0f\u529f\u80fd<\/li>\n\n\n\n<li>\u5728\u4fee\u6539\u4e3b\u9898\u6587\u4ef6\u524d\uff0c\u5efa\u8bae\u5148\u5907\u4efd<\/li>\n\n\n\n<li>\u4e0d\u540c\u4e3b\u9898\u53ef\u80fd\u9700\u8981\u8c03\u6574CSS\u6837\u5f0f\u4ee5\u8fbe\u5230\u6700\u4f73\u89c6\u89c9\u6548\u679c<\/li>\n<\/ul><p>\u901a\u8fc7\u4ee5\u4e0a\u5b8c\u6574\u7684\u914d\u7f6e\u548c\u4ee3\u7801\uff0c\u4f60\u7684WordPress\u7f51\u7ad9\u5c06\u80fd\u591f\u5145\u5206\u5229\u7528\u6587\u7ae0\u5f62\u5f0f\u529f\u80fd\uff0c\u4e3a\u4e0d\u540c\u7c7b\u578b\u7684\u5185\u5bb9\u63d0\u4f9b\u66f4\u52a0\u5408\u9002\u7684\u5c55\u793a\u65b9\u5f0f\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u4ecb\u7ecd\u5982\u4f55\u5728WordPress\u4e2d\u914d\u7f6e\u3001\u542f\u7528\u548c\u4f7f\u7528\u6587\u7ae0\u5f62\u5f0f\u5206\u7c7b\uff08Post Formats\uff09\uff0c\u4ece\u540e\u53f0\u914d\u7f6e\u5230\u524d\u53f0\u5c55\u793a\u7684\u5168\u6d41\u7a0b\u3002 \u7b2c\u4e00\u90e8\u5206\uff1a\u914d\u7f6e\u548c\u542f\u7528\u6587\u7ae0\u5f62\u5f0f 1.1 \u5728\u4e3b\u9898\u4e2d\u542f\u7528\u6587\u7ae0\u5f62\u5f0f\u652f\u6301 \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728\u4e3b\u9898\u7684functions.php\u6587\u4ef6\u4e2d\u542f\u7528\u6587\u7ae0\u5f62\u5f0f\u652f\u6301\uff1a 1.2 \u81ea\u5b9a\u4e49\u6587\u7ae0\u5f62\u5f0f\u663e\u793a\u540d\u79f0\uff08\u53ef\u9009\uff09 \u5982\u679c\u4f60\u5e0c\u671b\u81ea\u5b9a\u4e49\u6587..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"bjjc2nav":[14],"tuisongtax":[],"class_list":["post-4903","bjjc","type-bjjc","status-publish","hentry","bjjc2nav-jdztkf"],"acf":{"qian_art_seotitle":"WordPress\u6587\u7ae0\u5f62\u5f0f\u5206\u7c7b\uff08Post Formats\uff09\u7684\u542f\u7528\u548c\u5e94\u7528","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":"WordPress\u6587\u7ae0\u5f62\u5f0f\u5206\u7c7b\uff08Post Formats\uff09\u7684\u542f\u7528\u548c\u5e94\u7528"},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"\u6587\u7ae0\u5f62\u5f0f\u5206\u7c7b  \u542f\u52a8\u548c\u5e94\u7528","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":"\u6587\u7ae0\u5f62\u5f0f\u5206\u7c7b  \u542f\u52a8\u548c\u5e94\u7528"}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc\/4903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/types\/bjjc"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/media?parent=4903"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=4903"},{"taxonomy":"bjjc2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/bjjc2nav?post=4903"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=4903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}