{"id":32678,"date":"2024-11-25T13:38:21","date_gmt":"2024-11-25T05:38:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32678\/"},"modified":"2024-11-25T13:38:21","modified_gmt":"2024-11-25T05:38:21","slug":"%e5%9c%a8-wordpress-%e4%b8%ad%e5%88%9b%e5%bb%ba%e7%89%b9%e8%89%b2%e5%9b%be%e7%89%87%ef%bc%9a%e5%b0%86%e9%99%84%e4%bb%b6%e6%8f%90%e5%8d%87%e5%88%b0%e6%96%b0%e7%9a%84%e6%b0%b4%e5%b9%b3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32678\/","title":{"rendered":"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169381398961593.jpg\" class=\"aligncenter\" title=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe\" alt=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe\" \/><\/p>\n<p>\u5728\u672c\u7cfb\u5217\u4e2d\uff0c\u6211\u4ecb\u7ecd\uff1a<\/p>\n<ul>\n<li>\u4e3a\u9644\u4ef6\u5206\u914d\u7c7b\u522b\u548c\u5206\u7c7b\u6cd5\uff0c<\/li>\n<li>\u6309\u5206\u7c7b\u67e5\u8be2\u5a92\u4f53\u6587\u4ef6\uff0c\u4ee5\u4fbf\u60a8\u53ef\u4ee5\u5728\u81ea\u5b9a\u4e49\u5faa\u73af\u4e2d\u8f93\u51fa\u5b83\u4eec\uff0c<\/li>\n<li>\u4f7f\u7528\u56fe\u50cf\u5206\u7c7b\u67e5\u8be2\u5c06\u5176\u663e\u793a\u5728\u5b58\u6863\u9875\u9762\u4e0a\uff0c<\/li>\n<li>\u5c06\u56fe\u50cf\u6dfb\u52a0\u5230\u7c7b\u522b\u6216\u5206\u7c7b\u672f\u8bed\u4f5c\u4e3a\u7c7b\u522b\u6216\u672f\u8bed\u7684\u201c\u7279\u8272\u56fe\u50cf\u201d<\/li>\n<\/ul>\n<p>\u5728\u7b2c 1 \u90e8\u5206\u4e2d\uff0c\u6211\u6f14\u793a\u4e86\u5982\u4f55\u4e3a\u9644\u4ef6\u521b\u5efa\u65b0\u7684\u5206\u7c7b\u6cd5\u3002\u5728\u7b2c 2 \u90e8\u5206\u4e2d\uff0c\u6211\u5411\u60a8\u5c55\u793a\u4e86\u5982\u4f55\u4e3a\u6587\u6863\u521b\u5efa\u81ea\u5b9a\u4e49\u6a21\u677f\u6587\u4ef6\u5e76\u6dfb\u52a0\u4e00\u4e2a\u5faa\u73af\u6765\u663e\u793a\u6bcf\u4e2a\u6587\u6863\u7684\u5a92\u4f53\u6587\u4ef6\u7684\u94fe\u63a5\uff0c\u5728\u7b2c 3 \u90e8\u5206\u4e2d\uff0c\u6211\u4e3a gallery-category \u521b\u5efa\u4e86\u4e00\u4e2a\u81ea\u5b9a\u4e49\u6a21\u677f\u6587\u4ef6\u5206\u7c7b\u6cd5\uff0c\u5c06\u5177\u6709\u7ed9\u5b9a\u672f\u8bed\u7684\u6240\u6709\u56fe\u50cf\u663e\u793a\u4e3a\u753b\u5eca\u6837\u5f0f\u7684\u5b58\u6863\u9875\u9762\u3002<\/p>\n<p>\u5728\u6700\u540e\u4e00\u90e8\u5206\u4e2d\uff0c\u6211\u5c06\u6f14\u793a\u4e00\u4e9b\u7565\u6709\u4e0d\u540c\u7684\u5185\u5bb9\uff1a\u5982\u4f55\u4e3a\u56fe\u50cf\u5206\u914d\u7c7b\u522b\uff0c\u7136\u540e\u7f16\u8f91\u7c7b\u522b\u7684\u5b58\u6863\u6a21\u677f\u4ee5\u5c06\u8be5\u56fe\u50cf\u663e\u793a\u4e3a\u8be5\u7c7b\u522b\u7684\u201c\u7279\u8272\u56fe\u50cf\u201d\u3002\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528\u975e\u5e38\u7c7b\u4f3c\u7684\u6280\u672f\u5bf9\u6807\u7b7e\u6216\u5206\u7c7b\u672f\u8bed\u6267\u884c\u6b64\u64cd\u4f5c\u3002<\/p>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u5c06\u521b\u5efa\u4e00\u4e2a\u4e3b\u9898\uff0c\u8be5\u4e3b\u9898\u5c06\u662f\u4e8c\u5341\u56db\u5c81\u7684\u5b50\u4e3b\u9898\u3002\u8be5\u4e3b\u9898\u5c06\u5305\u62ec\u4e00\u4e2a\u51fd\u6570\u6587\u4ef6\u548c\u4e00\u4e2a\u7528\u4e8e\u7c7b\u522b\u5b58\u6863\u7684\u81ea\u5b9a\u4e49\u6a21\u677f\u6587\u4ef6\u3002\u60a8\u53ef\u4ee5\u5728\u4ee3\u7801\u5305\u4e2d\u4e0b\u8f7d\u8be5\u4e3b\u9898\u3002<\/p>\n<h2>\u60a8\u9700\u8981\u4ec0\u4e48<\/h2>\n<p>\u8981\u5b66\u4e60\u672c\u6559\u7a0b\uff0c\u60a8\u9700\u8981\u5177\u5907\u4ee5\u4e0b\u6761\u4ef6\uff1a<\/p>\n<ul>\n<li>WordPress \u7684\u5f00\u53d1\u5b89\u88c5<\/li>\n<li>FTP \u8bbf\u95ee\uff08\u6216\u8005 MAMP \u6216\u7c7b\u4f3c\u7684\uff0c\u5982\u679c\u60a8\u5728\u672c\u5730\u5de5\u4f5c\uff09<\/li>\n<li>\u4ee3\u7801\u7f16\u8f91\u5668<\/li>\n<\/ul>\n<h2> <span>1.<\/span> \u5c06\u7c7b\u522b\u5e94\u7528\u4e8e\u9644\u4ef6<\/h2>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cWordPress \u4e0d\u5141\u8bb8\u60a8\u4e3a\u9644\u4ef6\u5206\u914d\u7c7b\u522b\u548c\u6807\u7b7e\uff0c\u800c\u5728\u672c\u6559\u7a0b\u4e2d\u60a8\u9700\u8981\u80fd\u591f\u6267\u884c\u6b64\u64cd\u4f5c\u3002\u5e78\u8fd0\u7684\u662f\uff0c\u8fd9\u4e2a\u95ee\u9898\u5f88\u5bb9\u6613\u4fee\u590d\uff0c\u6b63\u5982\u6211\u5728\u4e4b\u524d\u5173\u4e8e\u4e3a\u9644\u4ef6\u5206\u914d\u7c7b\u522b\u548c\u6807\u7b7e\u7684\u6559\u7a0b\u4e2d\u6240\u6f14\u793a\u7684\u90a3\u6837\u3002<\/p>\n<p><em>\u6ce8\u610f\uff1a\u6b64\u6280\u672f\u9002\u7528\u4e8e\u6807\u7b7e\u548c\u7c7b\u522b\uff0c\u5982\u679c\u60a8\u4f7f\u7528\u81ea\u5df1\u7684\u5206\u7c7b\u6cd5\u6267\u884c\u6b64\u64cd\u4f5c\uff0c\u5219\u9700\u8981\u5728\u6ce8\u518c\u65f6\u5c06\u9644\u4ef6\u6307\u5b9a\u4e3a\u5206\u7c7b\u6cd5\u9002\u7528\u7684\u5e16\u5b50\u7c7b\u578b\u3002\u60a8\u53ef\u4ee5\u6309\u7167\u672c\u7cfb\u5217\u7684\u7b2c\u4e00\u90e8\u5206\u6765\u5b8c\u6210\u6b64\u64cd\u4f5c\u3002<\/em><\/p>\n<p>\u5728\u60a8\u7684\u4e3b\u9898\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a functions.php \u7684\u6587\u4ef6\uff0c\u5e76\u5411\u5176\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>&lt;?php \/\/ add categories to attachments  \nfunction wptp_add_categories_to_attachments() {\n      register_taxonomy_for_object_type( 'category', 'attachment' );  \n}  \nadd_action( 'init' , 'wptp_add_categories_to_attachments' ); \n?&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u4f7f\u7528 register_taxonomy_for_object_type() \u51fd\u6570\u5411\u9644\u4ef6\u6dfb\u52a0\u7c7b\u522b\u3002\u73b0\u5728\uff0c\u5f53\u60a8\u67e5\u770b\u5a92\u4f53\u5e93\u5c4f\u5e55\u65f6\uff0c\u60a8\u5c06\u770b\u5230\u7c7b\u522b\u5df2\u542f\u7528\u3002<\/p>\n<p>\u4e0b\u4e00\u6b65\u662f\u6dfb\u52a0\u4e00\u4e9b\u56fe\u50cf &#8211; \u6bcf\u4e2a\u7c7b\u522b\u53ea\u9700\u6dfb\u52a0\u4e00\u4e2a\u56fe\u50cf\u3002\u60a8\u8fd8\u9700\u8981\u6dfb\u52a0\u53e6\u4e00\u4e2a\u540d\u4e3a\u201c\u7cbe\u9009\u201d\u7684\u7c7b\u522b\uff0c\u5e76\u786e\u4fdd\u60a8\u60f3\u8981\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u4f7f\u7528\u7684\u6bcf\u4e2a\u56fe\u50cf\u4e5f\u5c5e\u4e8e\u8be5\u7c7b\u522b\u3002<\/p>\n<p>\u4e0b\u9762\u60a8\u53ef\u4ee5\u770b\u5230\u4e00\u4e2a\u793a\u4f8b\u5a92\u4f53\u7f16\u8f91\u5c4f\u5e55\uff0c\u5176\u4e2d\u663e\u793a\u4e86\u7c7b\u522b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169381398977455.jpg\" class=\"aligncenter\" title=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe1\" alt=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe1\" \/><br \/>\n<img decoding=\"async\" style=\"max-width:90%\" src=\"https:\/\/www.php.cn\/uploads\/20230829\/169325571464ed082238feb.jpg\" class=\"aligncenter\" title=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe2\" alt=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe2\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169381398924153.jpg\" class=\"aligncenter\" title=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe3\" alt=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe3\" \/>  <\/p>\n<p>\u60a8\u8fd8\u53ef\u4ee5\u67e5\u770b\u6211\u5206\u914d\u4e86\u6b63\u786e\u7c7b\u522b\u7684\u6240\u6709\u56fe\u50cf\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169381398965297.jpg\" class=\"aligncenter\" title=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe4\" alt=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe4\" \/><br \/>\n<img decoding=\"async\" style=\"max-width:90%\" src=\"https:\/\/www.php.cn\/uploads\/20230829\/169325572164ed08299f1c3.jpg\" class=\"aligncenter\" title=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe5\" alt=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe5\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169381399033425.jpg\" class=\"aligncenter\" title=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe6\" alt=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe6\" \/>  <\/p>\n<p>\u6700\u540e\uff0c\u6211\u5c06\u5411\u6211\u7684\u7f51\u7ad9\u6dfb\u52a0\u4e00\u4e9b\u865a\u62df\u5e16\u5b50\uff0c\u5e76\u5c06\u5b83\u4eec\u653e\u5165\u76f8\u5173\u7c7b\u522b\u4e2d\uff0c\u4ee5\u4fbf\u5728\u6211\u7684\u5b58\u6863\u9875\u9762\u4e2d\u663e\u793a\u4e00\u4e9b\u5185\u5bb9\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169381399070699.jpg\" class=\"aligncenter\" title=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe7\" alt=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe7\" \/><br \/>\n<img decoding=\"async\" style=\"max-width:90%\" src=\"https:\/\/www.php.cn\/uploads\/20230829\/169325572864ed083076365.jpg\" class=\"aligncenter\" title=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe8\" alt=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe8\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169381399049387.jpg\" class=\"aligncenter\" title=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe9\" alt=\"\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\u63d2\u56fe9\" \/>  <\/p>\n<h2> <span>2.<\/span>\u521b\u5efa\u7c7b\u522b\u6a21\u677f<\/h2>\n<p>\u4e0b\u4e00\u6b65\u662f\u521b\u5efa\u81ea\u5b9a\u4e49\u7c7b\u522b\u6a21\u677f\u3002\u7531\u4e8e\u6211\u7684\u4e3b\u9898\u662f\u4e8c\u5341\u56db\u7684\u5b50\u4e3b\u9898\uff0c\u6211\u5c06\u590d\u5236\u8be5\u4e3b\u9898\u7684 category.php \u6587\u4ef6\u5e76\u5c06\u5176\u590d\u5236\u5230\u6211\u7684\u5b50\u4e3b\u9898\uff0c\u5e76\u5bf9\u5f00\u5934\u6ce8\u91ca\u8fdb\u884c\u4e00\u4e9b\u66f4\u6539\uff1a<\/p>\n<pre>&lt;?php \/**   \n * The template for displaying Category pages   \n * Custom template which displays a featured image first.   \n * Supports Part 4 of tutorial series on Advanced Use of Images in WordPress for WPTutsplus   \n *\/ get_header();  ?&gt;&lt;section class=\"content-area\" id=\"primary\"&gt;&lt;div class=\"site-content\" id=\"content\" role=\"main\"&gt;\n&lt;?php if ( have_posts() ) : ?&gt;&lt;header class=\"archive-header\"&gt;&lt;h1 class=\"archive-title\"&gt;&lt;\/h1&gt;\n        &lt;?php \/\/ Show an optional term description.\n          $term_description = term_description();\n          if ( ! empty( $term_description ) ) :\n            printf( '&lt;div class=\"taxonomy-description\"&gt;%s&lt;\/header&gt;\n&lt;\/div&gt;', $term_description );\n          endif;\n        ?&amp;gt;\n    &lt;!-- .archive-header --&gt;\n\n&lt;?php \/\/ Start the Loop. \t\t\t\t\t   \nwhile ( have_posts() ) : the_post(); \t\t\t\t\t     \n      \/* \t\t\t\t\t       \n       * Include the post format-specific template for the content. If you want to \t\t\t\t\t            \n       * use this in a child theme, then include a file called called content-___.php \t\t\t\t\t            \n       * (where ___ is the post format) and that will be used instead. \t\t\t\t\t       \n       *\/ \t\t\t\t\t     \n      get_template_part( 'content', get_post_format() ); \t\t\t\t\t   \n    endwhile; \t\t\t\n\t\t   \n    \/\/ Previous\/next page navigation. \t\t\t\t\t   \n    twentyfourteen_paging_nav();\t\t\t   \n  else : \t\t\t\t\t     \n    \/\/ If no content, include the \"No posts found\" template. \t\t\t\t\t              \n    get_template_part( 'content', 'none' ); \t\t\t\t   \n  endif;    \n  ?&gt;&lt;!-- #content --&gt;&lt;\/section&gt;&lt;!-- #primary --&gt;&lt;?php get_sidebar( 'content' ); get_sidebar(); get_footer(); ?&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<h2> <span>3.<\/span>\u5411\u7c7b\u522b\u6a21\u677f\u6dfb\u52a0\u81ea\u5b9a\u4e49\u67e5\u8be2<\/h2>\n<p>\u5728\u4e3b\u5faa\u73af\u4e0a\u65b9\uff0c\u4f7f\u7528 WP_Query \u6dfb\u52a0\u81ea\u5b9a\u4e49\u5faa\u73af\u3002\u5728\u7ed3\u675f \u6807\u8bb0\u540e\u63d2\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre>&lt;?php \/\/ display a featured image for the category  \n\/\/ identify the current category  \n$currentcat = get_queried_object(); \n$currentcatname = $currentcat-&gt;slug;\n?&amp;gt;\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4f7f\u7528 get_queried_object() \u6807\u8bc6\u5f53\u524d\u663e\u793a\u7684\u7c7b\u522b\u3002<\/p>\n<p>\u4e0b\u9762\uff0c\u4f7f\u7528 WP_Query \u5b9a\u4e49\u81ea\u5b9a\u4e49\u67e5\u8be2\u7684\u53c2\u6570\uff1a<\/p>\n<pre>&lt;?php \/\/ define query arguments for the featured image    \n$args = array( \t     \n    'post_type' =&gt; 'attachment',\n    'post_status' =&amp;gt; 'inherit',\n    'category_name' =&amp;gt; $currentcatname,\n  );\n  $query = new WP_Query( $args );\n?&amp;gt;\n<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u6807\u8bc6\u5f53\u524d\u7c7b\u522b\u4ee5\u53ca\u201c\u7279\u8272\u201d\u7c7b\u522b\u4e2d\u7684\u6240\u6709\u9644\u4ef6\u3002\u8bf7\u6ce8\u610f\uff0c\u7531\u4e8e WordPress \u8bbe\u7f6e\u9644\u4ef6\u5e16\u5b50\u72b6\u6001\u7684\u65b9\u5f0f\uff0c\u60a8\u9700\u8981\u5305\u542b &#8216;post_status&#8217; =&gt; &#8216;inherit&#8217; \u4f5c\u4e3a\u53c2\u6570\u3002<\/p>\n<p>\u73b0\u5728\u5728\u6b64\u4e0b\u65b9\u6dfb\u52a0\u5faa\u73af\uff1a<\/p>\n<pre>&lt;?php \/\/ The Loop  while ( $query-&gt;have_posts() ) : $query-&amp;gt;the_post();\n  \/\/ define attributes for image display\n  $imgattr = array(\n\t\t'alt'   =&amp;gt; trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ),\n\t);\n\n  \/\/ output the image ?&amp;gt;\n  &lt;div class=\"category-image\"&gt;&lt;\/div&gt;\n&lt;?php endwhile;  \n\/\/ reset the query so the default query can be run  \nwp_reset_postdata(); ?&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u786e\u4fdd\u60a8\u4e0d\u8981\u9519\u8fc7\u6700\u540e\u7684 wp_reset_postdata() \uff0c\u5426\u5219\u7c7b\u522b\u5b58\u6863\u7684\u4e3b\u67e5\u8be2\u5c06\u65e0\u6cd5\u5de5\u4f5c\u3002<\/p>\n<p>\u6dfb\u52a0\u5b8c\u6240\u6709\u8fd9\u4e9b\u540e\uff0c\u4fdd\u5b58\u60a8\u7684\u7c7b\u522b\u6a21\u677f\u5e76\u67e5\u770b\u60a8\u7684\u7c7b\u522b\u5b58\u6863\u9875\u9762\u4e4b\u4e00\u3002\u5b83\u5e94\u8be5\u7c7b\u4f3c\u4e8e\u672c\u6559\u7a0b\u5f00\u5934\u7684\u5c4f\u5e55\u622a\u56fe\u3002<\/p>\n<h2>\u6458\u8981<\/h2>\n<p>\u5728\u8fd9\u4e2a\u7531\u56db\u4e2a\u6559\u7a0b\u7ec4\u6210\u7684\u7cfb\u5217\u4e2d\uff0c\u6211\u6f14\u793a\u4e86\u4e00\u4e9b\u5728 WordPress \u4e2d\u5904\u7406\u56fe\u50cf\u7684\u9ad8\u7ea7\u6280\u672f\u3002\u5176\u4e2d\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u6ce8\u518c\u4e13\u95e8\u7528\u4e8e\u9644\u4ef6\u7684\u5206\u7c7b<\/li>\n<li>\u4f7f\u7528\u81ea\u5b9a\u4e49\u6a21\u677f\u521b\u5efa dosucmtn \u5217\u8868\u9875\u9762<\/li>\n<li>\u518d\u6b21\u4f7f\u7528\u81ea\u5b9a\u4e49\u6a21\u677f\u521b\u5efa\u56fe\u5e93\u9875\u9762\u4ee5\u663e\u793a\u7ed9\u5b9a\u7c7b\u522b\u4e2d\u7684\u56fe\u50cf<\/li>\n<li>\u4e3a\u6bcf\u4e2a\u7c7b\u522b\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\u5e76\u5c06\u5176\u663e\u793a\u5728\u7c7b\u522b\u5b58\u6863\u9875\u9762\u4e0a\u3002<\/li>\n<\/ul>\n<p>\u6b63\u5982\u60a8\u6240\u89c1\uff0c\u60a8\u53ef\u4ee5\u5728 WordPress \u4e2d\u5bf9\u56fe\u50cf\u548c\u5a92\u4f53\u6267\u884c\u66f4\u591a\u64cd\u4f5c\uff0c\u800c\u4e0d\u4ec5\u4ec5\u662f\u5c06\u5b83\u4eec\u9644\u52a0\u5230\u5e16\u5b50\u6216\u5c06\u5b83\u4eec\u7528\u4f5c\u7279\u8272\u56fe\u50cf\u3002\u53ea\u8981\u53d1\u6325\u4e00\u70b9\u60f3\u8c61\u529b\uff0c\u60a8\u5c31\u53ef\u4ee5\u50cf\u4efb\u4f55\u5176\u4ed6\u5e16\u5b50\u7c7b\u578b\u4e00\u6837\u67e5\u8be2\u5b83\u4eec\uff0c\u5e76\u8f93\u51fa\u6587\u6863\u6216\u663e\u793a\u56fe\u50cf\u7684\u94fe\u63a5\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5728 WordPress \u4e2d\u521b\u5efa\u201c\u7279\u8272\u56fe\u7247\u201d\uff1a\u5c06\u9644\u4ef6\u63d0\u5347\u5230\u65b0\u7684\u6c34\u5e73\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\u672c\u7cfb\u5217\u4e2d\uff0c\u6211\u4ecb\u7ecd\uff1a \u4e3a\u9644\u4ef6\u5206\u914d\u7c7b\u522b\u548c\u5206\u7c7b\u6cd5\uff0c \u6309\u5206\u7c7b\u67e5\u8be2\u5a92\u4f53\u6587\u4ef6\uff0c\u4ee5\u4fbf\u60a8\u53ef\u4ee5\u5728\u81ea\u5b9a\u4e49\u5faa\u73af\u4e2d\u8f93\u51fa\u5b83\u4eec\uff0c \u4f7f\u7528\u56fe\u50cf\u5206\u7c7b\u67e5\u8be2\u5c06\u5176\u663e\u793a\u5728\u5b58\u6863\u9875\u9762\u4e0a\uff0c \u5c06\u56fe\u50cf\u6dfb\u52a0\u5230\u7c7b\u522b\u6216\u5206\u7c7b\u672f\u8bed\u4f5c\u4e3a\u7c7b\u522b\u6216\u672f\u8bed\u7684\u201c\u7279\u8272\u56fe\u50cf\u201d \u5728\u7b2c 1 \u90e8\u5206\u4e2d\uff0c\u6211\u6f14\u793a\u4e86\u5982\u4f55\u4e3a\u9644\u4ef6\u521b\u5efa\u65b0\u7684\u5206\u7c7b\u6cd5\u3002\u5728\u7b2c 2 \u90e8\u5206\u4e2d\uff0c\u6211\u5411\u60a8\u5c55\u793a\u4e86\u5982\u4f55\u4e3a\u6587\u6863\u521b\u5efa\u81ea\u5b9a\u4e49\u6a21\u677f\u6587\u4ef6\u5e76\u6dfb\u52a0\u4e00\u4e2a\u5faa\u73af\u6765\u663e\u793a\u6bcf\u4e2a\u6587\u6863\u7684\u5a92\u4f53\u6587\u4ef6\u7684\u94fe\u63a5\uff0c\u5728\u7b2c 3 \u90e8\u5206\u4e2d\uff0c\u6211\u4e3a gallery-category \u521b\u5efa\u4e86\u4e00\u4e2a\u81ea\u5b9a\u4e49\u6a21\u677f\u6587\u4ef6\u5206\u7c7b\u6cd5\uff0c\u5c06\u5177\u6709\u7ed9\u5b9a\u672f\u8bed\u7684\u6240\u6709\u56fe\u50cf\u663e\u793a\u4e3a\u753b\u5eca\u6837\u5f0f\u7684\u5b58\u6863\u9875\u9762\u3002 \u5728\u6700\u540e\u4e00\u90e8\u5206\u4e2d\uff0c\u6211\u5c06\u6f14\u793a\u4e00\u4e9b\u7565\u6709\u4e0d\u540c\u7684\u5185\u5bb9\uff1a\u5982\u4f55\u4e3a\u56fe\u50cf\u5206\u914d\u7c7b\u522b\uff0c\u7136\u540e\u7f16\u8f91\u7c7b\u522b\u7684\u5b58\u6863\u6a21\u677f\u4ee5\u5c06\u8be5\u56fe\u50cf\u663e\u793a\u4e3a\u8be5\u7c7b\u522b\u7684\u201c\u7279\u8272\u56fe\u50cf\u201d\u3002\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528\u975e\u5e38\u7c7b\u4f3c\u7684\u6280\u672f\u5bf9\u6807\u7b7e\u6216\u5206\u7c7b\u672f\u8bed\u6267\u884c\u6b64\u64cd\u4f5c\u3002 \u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u5c06\u521b\u5efa\u4e00\u4e2a\u4e3b\u9898\uff0c\u8be5\u4e3b\u9898\u5c06\u662f\u4e8c\u5341\u56db\u5c81\u7684\u5b50\u4e3b\u9898\u3002\u8be5\u4e3b\u9898\u5c06\u5305\u62ec\u4e00\u4e2a\u51fd\u6570\u6587\u4ef6\u548c\u4e00\u4e2a\u7528\u4e8e\u7c7b\u522b\u5b58\u6863\u7684\u81ea\u5b9a\u4e49\u6a21\u677f\u6587\u4ef6\u3002\u60a8\u53ef\u4ee5\u5728\u4ee3\u7801\u5305\u4e2d\u4e0b\u8f7d\u8be5\u4e3b\u9898\u3002 \u60a8\u9700\u8981\u4ec0\u4e48 \u8981\u5b66\u4e60\u672c\u6559\u7a0b\uff0c\u60a8\u9700\u8981\u5177\u5907\u4ee5\u4e0b\u6761\u4ef6\uff1a WordPress \u7684\u5f00\u53d1\u5b89\u88c5 FTP \u8bbf\u95ee\uff08\u6216\u8005 MAMP \u6216\u7c7b\u4f3c\u7684\uff0c\u5982\u679c\u60a8\u5728\u672c\u5730\u5de5\u4f5c\uff09 \u4ee3\u7801\u7f16\u8f91\u5668 1. \u5c06\u7c7b\u522b\u5e94\u7528\u4e8e\u9644\u4ef6 \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cWordPress \u4e0d\u5141\u8bb8\u60a8\u4e3a\u9644\u4ef6\u5206\u914d\u7c7b\u522b\u548c\u6807\u7b7e\uff0c\u800c\u5728\u672c\u6559\u7a0b\u4e2d\u60a8\u9700\u8981\u80fd\u591f\u6267\u884c\u6b64\u64cd\u4f5c\u3002\u5e78\u8fd0\u7684\u662f\uff0c\u8fd9\u4e2a\u95ee\u9898\u5f88\u5bb9\u6613\u4fee\u590d\uff0c\u6b63\u5982\u6211\u5728\u4e4b\u524d\u5173\u4e8e\u4e3a\u9644\u4ef6\u5206\u914d\u7c7b\u522b\u548c\u6807\u7b7e\u7684\u6559\u7a0b\u4e2d\u6240\u6f14\u793a\u7684\u90a3\u6837\u3002 \u6ce8\u610f\uff1a\u6b64\u6280\u672f\u9002\u7528\u4e8e\u6807\u7b7e\u548c\u7c7b\u522b\uff0c\u5982\u679c\u60a8\u4f7f\u7528\u81ea\u5df1\u7684\u5206\u7c7b\u6cd5\u6267\u884c\u6b64\u64cd\u4f5c\uff0c\u5219\u9700\u8981\u5728\u6ce8\u518c\u65f6\u5c06\u9644\u4ef6\u6307\u5b9a\u4e3a\u5206\u7c7b\u6cd5\u9002\u7528\u7684\u5e16\u5b50\u7c7b\u578b\u3002\u60a8\u53ef\u4ee5\u6309\u7167\u672c\u7cfb\u5217\u7684\u7b2c\u4e00\u90e8\u5206\u6765\u5b8c\u6210\u6b64\u64cd\u4f5c\u3002 \u5728\u60a8\u7684\u4e3b\u9898\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a functions.php \u7684\u6587\u4ef6\uff0c\u5e76\u5411\u5176\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a &lt;?php \/\/ add categories to attachments function wptp_add_categories_to_attachments() { register_taxonomy_for_object_type( &#8216;category&#8217;, &#8216;attachment&#8217; ); } add_action( &#8216;init&#8217; , &#8216;wptp_add_categories_to_attachments&#8217; ); ?&gt; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u4f7f\u7528 [&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-32678","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32678","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=32678"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32678\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}