{"id":1952,"date":"2025-06-10T18:14:35","date_gmt":"2025-06-10T10:14:35","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/wpdt\/1952.html"},"modified":"2025-06-10T18:14:35","modified_gmt":"2025-06-10T10:14:35","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-wordpress-%e4%b8%ad%e6%98%be%e7%a4%ba%e5%bd%93%e5%89%8d%e5%88%86%e7%b1%bb%e6%a0%87%e9%a2%98%e3%80%81url-%e5%8f%8a%e5%85%b6%e4%bb%96%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/post\/1952.html","title":{"rendered":"\u5982\u4f55\u5728 WordPress \u4e2d\u663e\u793a\u5f53\u524d\u5206\u7c7b\u6807\u9898\u3001URL \u53ca\u5176\u4ed6\u4fe1\u606f"},"content":{"rendered":"<div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--1\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/dyA-1-400x300.jpg\" alt=\"Bug&#32534;&#35793;&#29422;\" class=\"wp-image-1842\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<p class=\"my-0\">Bug&#32534;&#35793;&#29422;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#35201;&#22312; WordPress &#32593;&#31449;&#19978;&#26174;&#31034;&#24403;&#21069;&#20998;&#31867;&#30340;&#26631;&#39064;&#12289;URL &#20197;&#21450;&#20854;&#20182;&#30456;&#20851;&#20449;&#24687;&#65292;&#20320;&#21487;&#20197;&#20351;&#29992;&#19968;&#20123;&#20869;&#32622;&#30340;&#21151;&#33021;&#21644;&#25554;&#20214;&#26469;&#23454;&#29616;&#36825;&#19968;&#30446;&#26631;&#12290;&#20197;&#19979;&#26159;&#19968;&#31181;&#24120;&#35265;&#30340;&#26041;&#27861;&#65306;<\/p>\n<h3>&#27493;&#39588; 1: &#28155;&#21152;&#20998;&#31867;&#26631;&#31614;<\/h3>\n<p>&#39318;&#20808;&#65292;&#22312; WordPress &#30340;&#21518;&#21488;&#31649;&#29702;&#38754;&#26495;&#20013;&#28155;&#21152;&#19968;&#20010;&#33258;&#23450;&#20041;&#26631;&#31614;&#65288;Custom Post Type&#65289;&#65292;&#29992;&#20110;&#23384;&#20648;&#19982;&#20998;&#31867;&#30456;&#20851;&#30340;&#25968;&#25454;&#12290;<\/p>\n<h4>&#20351;&#29992;&#31034;&#20363;&#20195;&#30721;&#65306;<\/h4>\n<pre><code class=\"language-php\">\/\/ &#25554;&#20837;&#21040; functions.php &#25991;&#20214;&#20013;\nfunction add_custom_taxonomy() {\n    register_taxonomy_for_object_type( 'category', 'custom-post-type-name' );\n}\nadd_action('init', 'add_custom_taxonomy');<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#20363;&#23376;&#20013;&#65292;&#25105;&#20204;&#27880;&#20876;&#20102;&#19968;&#20010;&#21517;&#20026; <code>custom-post-type-name<\/code> &#30340;&#33258;&#23450;&#20041;&#26631;&#31614;&#65292;&#20854;&#20013; <code>category<\/code> &#26159;&#20998;&#31867;&#12290;<\/p>\n<h3>&#27493;&#39588; 2: &#21019;&#24314;&#20998;&#31867;&#26631;&#31614;&#20869;&#23481;<\/h3>\n<p>&#25509;&#19979;&#26469;&#65292;&#21019;&#24314;&#19968;&#20010;&#27169;&#26495;&#25991;&#20214;&#26469;&#23637;&#31034;&#36825;&#20010;&#26631;&#31614;&#30340;&#20869;&#23481;&#12290;<\/p>\n<h4>&#31034;&#20363;&#27169;&#26495;&#25991;&#20214; (single-custom-post-type.php)&#65306;<\/h4>\n<pre><code class=\"language-php\">&lt;?php get_header(); ?&gt;\n\n&lt;div class=\"container\"&gt;\n    &lt;div class=\"row\"&gt;\n        &lt;?php while ( have_posts() ) : the_post(); ?&gt;\n            &lt;!-- &#26816;&#26597;&#26159;&#21542;&#20026;&#20998;&#31867;&#39029;&#38754; --&gt;\n            &lt;?php if(is_category()): ?&gt;\n                &lt;h1&gt;&lt;?php the_title(); ?&gt;&lt;\/h1&gt;\n                &lt;p&gt;&lt;a href=\"&lt;?php echo get_category_link(get_queried_object_id()); ?&gt;\"&gt;&lt;?php echo get_the_category_list(', '); ?&gt;&lt;\/a&gt;&lt;\/p&gt;\n                &lt;!-- &#26174;&#31034;&#26356;&#22810;&#20998;&#31867;&#20449;&#24687; --&gt;\n                &lt;ul&gt;\n                    &lt;?php $categories = get_the_category();\n                        foreach ($categories as $category) { ?&gt;\n                            &lt;li&gt;&lt;?php echo $category-&gt;name; ?&gt;&lt;\/li&gt;\n                    &lt;?php } ?&gt;\n                &lt;\/ul&gt;\n            &lt;?php endif; ?&gt;\n        &lt;?php endwhile; ?&gt;\n    &lt;\/div&gt;\n&lt;\/div&gt;\n\n&lt;?php get_footer(); ?&gt;<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#27169;&#26495;&#25991;&#20214;&#20013;&#65292;&#25105;&#20204;&#26816;&#26597;&#20102;&#24403;&#21069;&#39029;&#38754;&#26159;&#21542;&#26159;&#20998;&#31867;&#39029;&#38754; (<code>is_category()<\/code> &#20989;&#25968;)&#65292;&#22914;&#26524;&#26159;&#65292;&#21017;&#26174;&#31034;&#20998;&#31867;&#30340;&#26631;&#39064;&#21644;&#38142;&#25509;&#20197;&#21450;&#25152;&#26377;&#23376;&#20998;&#31867;&#30340;&#20449;&#24687;&#12290;<\/p>\n<h3>&#27493;&#39588; 3: &#22312;&#39318;&#39029;&#25110;&#29305;&#23450;&#39029;&#38754;&#26174;&#31034;&#20998;&#31867;&#20449;&#24687;<\/h3>\n<p>&#22914;&#26524;&#20320;&#24076;&#26395;&#22312;&#39318;&#39029;&#25110;&#20854;&#20182;&#29305;&#23450;&#39029;&#38754;&#26174;&#31034;&#36825;&#20123;&#20998;&#31867;&#20449;&#24687;&#65292;&#21487;&#20197;&#22312;&#30456;&#24212;&#39029;&#38754;&#30340;&#27169;&#26495;&#25991;&#20214;&#20013;&#35843;&#29992;&#19978;&#36848;&#20195;&#30721;&#12290;<\/p>\n<h4>&#31034;&#20363;&#65306;&#22312;&#39318;&#39029; (index.php)<\/h4>\n<pre><code class=\"language-php\">&lt;?php get_header(); ?&gt;\n&lt;main role=\"main\" class=\"container\"&gt;\n    &lt;section class=\"post-list\"&gt;\n        &lt;?php if(have_posts()) : while(have_posts()) : the_post(); ?&gt;\n            &lt;?php if(is_category()): ?&gt;\n                &lt;article class=\"post\"&gt;\n                    &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;\/h2&gt;\n                    &lt;p&gt;&lt;a href=\"&lt;?php echo get_category_link(get_queried_object_id()); ?&gt;\"&gt;&lt;?php echo get_the_category_list(', '); ?&gt;&lt;\/a&gt;&lt;\/p&gt;\n                    &lt;ul&gt;\n                        &lt;?php $categories = get_the_category();\n                            foreach ($categories as $category) { ?&gt;\n                                &lt;li&gt;&lt;?php echo $category-&gt;name; ?&gt;&lt;\/li&gt;\n                        &lt;?php } ?&gt;\n                    &lt;\/ul&gt;\n                &lt;\/article&gt;\n            &lt;?php endif; ?&gt;\n        &lt;?php endwhile; endif; ?&gt;\n    &lt;\/section&gt;\n&lt;\/main&gt;\n&lt;?php get_footer(); ?&gt;<\/code><\/pre>\n<h3>&#24635;&#32467;<\/h3>\n<p>&#36890;&#36807;&#20197;&#19978;&#27493;&#39588;&#65292;&#20320;&#21487;&#20197;&#22312; WordPress &#20013;&#21160;&#24577;&#22320;&#26174;&#31034;&#24403;&#21069;&#20998;&#31867;&#30340;&#26631;&#39064;&#12289;URL &#20197;&#21450;&#30456;&#20851;&#23376;&#20998;&#31867;&#20449;&#24687;&#12290;&#36825;&#19981;&#20165;&#22686;&#24378;&#20102;&#29992;&#25143;&#20307;&#39564;&#65292;&#36824;&#24110;&#21161;&#29992;&#25143;&#26356;&#22909;&#22320;&#20102;&#35299;&#32593;&#31449;&#30340;&#20869;&#23481;&#32467;&#26500;&#12290;&#35760;&#24471;&#26681;&#25454;&#23454;&#38469;&#38656;&#27714;&#35843;&#25972;&#20195;&#30721;&#20197;&#36866;&#24212;&#19981;&#21516;&#30340;&#39029;&#38754;&#24067;&#23616;&#21644;&#21151;&#33021;&#38656;&#27714;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--2\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/zp-400x300.jpg\" alt=\"&#40657;&#26495;&#21069;&#30340;Bug&#35821;&#27861;&#35762;&#24072;\" class=\"wp-image-1849\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<p class=\"my-0\">&#40657;&#26495;&#21069;&#30340;Bug&#35821;&#27861;&#35762;&#24072;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<h3>&#25945;&#26696;&#22823;&#32434;<\/h3>\n<ol>\n<li><strong>&#22522;&#30784;&#20171;&#32461;<\/strong>\n<ul>\n<li>&#31616;&#21333;&#20171;&#32461; WordPress &#21644;&#20854;&#26680;&#24515;&#21151;&#33021;&#12290;<\/li>\n<\/ul><\/li>\n<li><strong>&#20998;&#31867;&#31649;&#29702;&#22120;<\/strong>\n<ul>\n<li>&#22914;&#20309;&#21019;&#24314;&#21644;&#31649;&#29702; WordPress &#30340;&#20998;&#31867;&#12290;<\/li>\n<\/ul><\/li>\n<li><strong>&#20351;&#29992;&#20998;&#31867;&#26631;&#31614;<\/strong>\n<ul>\n<li>&#20998;&#31867;&#26631;&#31614;&#30340;&#21151;&#33021;&#21450;&#20854;&#20351;&#29992;&#26041;&#27861;&#12290;<\/li>\n<\/ul><\/li>\n<li><strong>&#26174;&#31034;&#20998;&#31867;&#20449;&#24687;<\/strong>\n<ul>\n<li>&#22914;&#20309;&#22312; WordPress &#39029;&#38754;&#19978;&#26174;&#31034;&#20998;&#31867;&#26631;&#39064;&#12289;URL &#20197;&#21450;&#20854;&#23427;&#30456;&#20851;&#20449;&#24687;&#12290;<\/li>\n<\/ul><\/li>\n<\/ol>\n<h3>&#35838;&#31243;&#30446;&#26631;<\/h3>\n<ul>\n<li>&#23398;&#20064;&#22914;&#20309;&#22312; WordPress &#20013;&#35774;&#32622;&#20998;&#31867;&#24182;&#26174;&#31034;&#23427;&#20204;&#30340;&#20449;&#24687;&#12290;<\/li>\n<li>&#25484;&#25569;&#20351;&#29992;&#20998;&#31867;&#26631;&#31614;&#26469;&#32654;&#21270;&#39029;&#38754;&#35774;&#35745;&#30340;&#33021;&#21147;&#12290;<\/li>\n<li>&#33021;&#22815;&#26681;&#25454;&#38656;&#35201;&#33258;&#23450;&#20041;&#26174;&#31034;&#20998;&#31867;&#20449;&#24687;&#30340;&#26041;&#24335;&#12290;<\/li>\n<\/ul>\n<h3>&#35762;&#35299;&#31034;&#20363;&#20195;&#30721;<\/h3>\n<h4>1. &#22522;&#30784;&#20171;&#32461;<\/h4>\n<pre><code class=\"language-php\">&lt;?php\n\/*\nPlugin Name: Category Management\nDescription: This plugin allows you to manage your WordPress categories.\nVersion: 1.0\nAuthor: Your Name\n*\/\n\n\/\/ &#27880;&#20876;&#20998;&#31867;&#26631;&#31614;\nfunction register_category() {\n    $labels = array(\n        'name' =&gt; _x('Categories', 'category name'),\n        'singular_name' =&gt; _x('Category', 'category singular name')\n    );\n\n    $args = array(\n        'label' =&gt; __('Categories', 'your-plugin-labels'),\n        'description' =&gt; __('List of all your categories.', 'your-plugin-description'),\n        'public' =&gt; true,\n        'show_ui' =&gt; true,\n        'show_in_menu' =&gt; true,\n        'menu_icon' =&gt; 'dashicons-category',\n        'capability_type' =&gt; 'post',\n        'hierarchical' =&gt; false,\n        'rewrite' =&gt; true,\n        'has_archive' =&gt; true,\n        'query_var' =&gt; true,\n        'supports' =&gt; array('title','editor','thumbnail')\n    );\n\n    register_post_type( 'category', $args );\n}\n\nadd_action( 'init', 'register_category' );<\/code><\/pre>\n<h4>2. &#20998;&#31867;&#31649;&#29702;&#22120;<\/h4>\n<pre><code class=\"language-php\">&lt;?php\n\/**\n * Displays a list of the category tree\n *\/\nfunction display_categories_tree() {\n\n    global $wp_query;\n\n    if ( ! empty( $wp_query-&gt;query_vars['cat'] ) ) { \/\/ Only show categories with a specified ID in the query\n        $categories = get_categories( array( 'hide_empty' =&gt; 0, 'orderby' =&gt; 'name', 'order' =&gt; 'ASC' ) );\n\n        foreach ( $categories as $category ) {\n            echo '&lt;li class=\"list-group-item\"&gt;&lt;a href=\"' . esc_url( get_term_link( $category ) ) . '\"&gt;' . esc_html( $category-&gt;name ) . '&lt;\/a&gt;&lt;\/li&gt;';\n        }\n    } else {\n        echo '&lt;div class=\"alert alert-info\"&gt;' . __( 'Please select a category from the drop-down menu or use the search bar to find it.', 'your-plugin-name' ) . '&lt;\/div&gt;';\n    }\n\n}<\/code><\/pre>\n<h4>3. &#20351;&#29992;&#20998;&#31867;&#26631;&#31614;<\/h4>\n<pre><code class=\"language-html\">&lt;div id=\"categories-tree\"&gt;\n    &lt;?php display_categories_tree(); ?&gt;\n&lt;\/div&gt;<\/code><\/pre>\n<h4>4. &#26174;&#31034;&#20998;&#31867;&#20449;&#24687;<\/h4>\n<pre><code class=\"language-html\">&lt;li class=\"list-group-item\"&gt;&lt;a href=\"&lt;?php echo esc_url(get_term_link($term)); ?&gt;\"&gt;&lt;?php echo esc_html($term-&gt;name); ?&gt;&lt;\/a&gt;&lt;\/li&gt;<\/code><\/pre>\n<h4>&#23454;&#25112;&#24212;&#29992;<\/h4>\n<ol>\n<li><strong>&#30331;&#24405;&#21040;&#24744;&#30340; WordPress &#20027;&#39064;&#32593;&#31449;<\/strong>&#12290;<\/li>\n<li><strong>&#21019;&#24314;&#19968;&#20010;&#26032;&#30340;&#20027;&#39064;&#25991;&#20214;&#22841;&#65292;&#21629;&#21517;&#20026; &#8220;mytheme&#8221;<\/strong>&#12290;<\/li>\n<li><strong>&#23558;&#19978;&#36848;&#20195;&#30721;&#22797;&#21046;&#31896;&#36148;&#21040; &#8220;mytheme&#8221; &#25991;&#20214;&#22841;&#19979;&#30340; <code>functions.php<\/code> &#25991;&#20214;&#20013;<\/strong>&#12290;<\/li>\n<li><strong>&#20445;&#23384;&#26356;&#25913;&#24182;&#28608;&#27963;&#20027;&#39064;<\/strong>&#12290;<\/li>\n<\/ol>\n<p>&#36890;&#36807;&#20197;&#19978;&#27493;&#39588;&#65292;&#24744;&#21487;&#20197;&#22312; WordPress &#20013;&#36731;&#26494;&#22320;&#28155;&#21152;&#12289;&#31649;&#29702;&#21644;&#23637;&#31034;&#20998;&#31867;&#20449;&#24687;&#20102;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bug&#32534;&#35793;&#29422; &#35201;&#22312; WordPress &#32593;&#31449;&#19978;&#26174;&#31034;&#24403;&#21069;&#20998;&#31867;&#30340;&#26631;&#39064;&#12289;U..<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[52,53],"tuisongtax":[],"class_list":["post-1952","post","type-post","status-publish","format-standard","hentry","category-wpdt","tag-ztjc","tag-ztmbpzjc"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/1952","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/comments?post=1952"}],"version-history":[{"count":0,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/1952\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/media?parent=1952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/categories?post=1952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=1952"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=1952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}