{"id":32829,"date":"2024-11-25T12:04:40","date_gmt":"2024-11-25T04:04:40","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32829\/"},"modified":"2024-11-25T12:04:40","modified_gmt":"2024-11-25T04:04:40","slug":"%e5%a6%82%e4%bd%95%e5%bc%80%e5%8f%91%e4%b8%80%e4%b8%aa%e8%87%aa%e5%8a%a8%e7%94%9f%e6%88%90%e9%97%ae%e7%ad%94%e7%b3%bb%e7%bb%9f%e7%9a%84wordpress%e6%8f%92%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32829\/","title":{"rendered":"\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u95ee\u7b54\u7cfb\u7edf\u7684WordPress\u63d2\u4ef6"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/465\/014\/169390036785767.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u95ee\u7b54\u7cfb\u7edf\u7684WordPress\u63d2\u4ef6\u63d2\u56fe\" alt=\"\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u95ee\u7b54\u7cfb\u7edf\u7684WordPress\u63d2\u4ef6\u63d2\u56fe\" \/><\/p>\n<p>\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u95ee\u7b54\u7cfb\u7edf\u7684WordPress\u63d2\u4ef6<\/p>\n<p>\u7b80\u4ecb\uff1a<br \/>\u5728\u73b0\u4ee3\u4e92\u8054\u7f51\u65f6\u4ee3\uff0c\u95ee\u7b54\u7f51\u7ad9\u53d8\u5f97\u8d8a\u6765\u8d8a\u53d7\u6b22\u8fce\u3002\u4e3a\u4e86\u6ee1\u8db3\u7528\u6237\u5bf9\u95ee\u9898\u548c\u7b54\u6848\u7684\u9700\u6c42\uff0c\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u95ee\u7b54\u7cfb\u7edf\u7684WordPress\u63d2\u4ef6\u3002\u901a\u8fc7\u8fd9\u4e2a\u63d2\u4ef6\uff0c\u60a8\u53ef\u4ee5\u65b9\u4fbf\u5730\u521b\u5efa\u4e00\u4e2a\u95ee\u7b54\u5e73\u53f0\uff0c\u4f7f\u60a8\u7684\u7f51\u7ad9\u66f4\u52a0\u4ea4\u4e92\u548c\u5177\u6709\u5438\u5f15\u529b\u3002<\/p>\n<p>\u6b65\u9aa4\u4e00\uff1a\u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u8d44\u6599\u7c7b\u578b\uff08Post Type\uff09<br \/>\u5728WordPress\u4e2d\uff0c\u81ea\u5b9a\u4e49\u7684\u8d44\u6599\u7c7b\u578b\u662f\u4e00\u79cd\u53ef\u4ee5\u6269\u5c55\u9ed8\u8ba4\u7684\u6587\u7ae0\u548c\u9875\u9762\u7684\u529f\u80fd\u3002\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cQuestion\u201d\u7684\u81ea\u5b9a\u4e49\u8d44\u6599\u7c7b\u578b\u3002<\/p>\n<pre>function create_question_post_type() {\n  $labels = array(\n    'name' =&amp;gt; 'Questions',\n    'singular_name' =&amp;gt; 'Question',\n    'add_new' =&amp;gt; 'Add New',\n    'add_new_item' =&amp;gt; 'Add New Question',\n    'edit_item' =&amp;gt; 'Edit Question',\n    'new_item' =&amp;gt; 'New Question',\n    'view_item' =&amp;gt; 'View Question',\n    'search_items' =&amp;gt; 'Search Questions',\n    'not_found' =&amp;gt; 'No questions found',\n    'not_found_in_trash' =&amp;gt; 'No questions found in trash',\n    'parent_item_colon' =&amp;gt; '',\n    'menu_name' =&amp;gt; 'Questions'\n  );\n\n  $args = array(\n    'labels' =&amp;gt; $labels,\n    'public' =&amp;gt; true,\n    'has_archive' =&amp;gt; true,\n    'rewrite' =&amp;gt; array('slug' =&amp;gt; 'questions'),\n    'supports' =&amp;gt; array('title', 'editor', 'author')\n  );\n\n  register_post_type('question', $args);\n}\n\nadd_action('init', 'create_question_post_type');<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6b65\u9aa4\u4e8c\uff1a\u521b\u5efa\u95ee\u9898\u548c\u7b54\u6848\u7684\u5143\u5b57\u6bb5\uff08Meta Fields\uff09<br \/>\u6211\u4eec\u9700\u8981\u4e3a\u95ee\u9898\u548c\u7b54\u6848\u6dfb\u52a0\u4e00\u4e9b\u989d\u5916\u7684\u4fe1\u606f\u5b57\u6bb5\uff0c\u4f8b\u5982\u95ee\u9898\u7684\u7c7b\u522b\u3001\u7b54\u6848\u7684\u4f5c\u8005\u7b49\u3002\u901a\u8fc7\u6dfb\u52a0\u5143\u5b57\u6bb5\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u7f16\u8f91\u95ee\u9898\u548c\u7b54\u6848\u65f6\u6dfb\u52a0\u548c\u7ba1\u7406\u8fd9\u4e9b\u989d\u5916\u7684\u4fe1\u606f\u5b57\u6bb5\u3002<\/p>\n<pre>function add_question_meta_fields() {\n  add_meta_box('question_category', 'Category', 'question_category_callback', 'question', 'side', 'default');\n}\n\nfunction question_category_callback($post) {\n  $value = get_post_meta($post-&amp;gt;ID, 'question_category', true);\n  echo '&lt;input type=\"text\" name=\"question_category\" value=\"' . esc_attr($value) . '\"&gt;';\n}\n\nfunction save_question_meta_fields($post_id) {\n  if (array_key_exists('question_category', $_POST)) {\n    update_post_meta(\n      $post_id,\n      'question_category',\n      sanitize_text_field($_POST['question_category'])\n    );\n  }\n}\n\nadd_action('add_meta_boxes_question', 'add_question_meta_fields');\nadd_action('save_post_question', 'save_question_meta_fields');<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6b65\u9aa4\u4e09\uff1a\u521b\u5efa\u95ee\u7b54\u7cfb\u7edf\u6a21\u677f<br \/>\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u95ee\u7b54\u7cfb\u7edf\u7684\u6a21\u677f\uff0c\u7528\u4e8e\u663e\u793a\u95ee\u9898\u548c\u7b54\u6848\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528WordPress\u7684\u6a21\u677f\u6587\u4ef6\uff08\u4f8b\u5982single-question.php\uff09\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002<\/p>\n<pre>&lt;?php \/* Template name: Question Template *\/ ?&gt;&lt;?php get_header(); ?&gt;&lt;div id=\"primary\"&gt;\n  &lt;main id=\"main\" class=\"site-main\" role=\"main\"&gt;&lt;?php while (have_posts()): the_post(); ?&gt;&lt;article id=\"post-&amp;lt;?php the_ID(); ?&amp;gt;\" post_class&gt;&amp;gt;\n        &lt;header class=\"entry-header\"&gt;&lt;h1 class=\"entry-title\"&gt;&lt;?php the_title(); ?&gt;&lt;\/h1&gt;\n        &lt;\/header&gt;&lt;div class=\"entry-content\"&gt;\n          &lt;?php the_content(); ?&gt;\n&lt;\/div&gt;\n\n        &lt;?php $answers = get_post_meta(get_the_ID(), 'answers', true); ?&gt;&lt;?php if (!empty($answers)): ?&gt;&lt;section class=\"answers\"&gt;&lt;h2&gt;Answers&lt;\/h2&gt;\n            &lt;ul&gt;\n&lt;?php foreach ($answers as $answer): ?&gt;&lt;li&gt;&lt;?php echo $answer; ?&gt;&lt;\/li&gt;\n              &lt;?php endforeach; ?&gt;\n&lt;\/ul&gt;&lt;\/section&gt;&lt;?php endif; ?&gt;&lt;\/article&gt;&lt;?php endwhile; ?&gt;&lt;\/main&gt;\n&lt;\/div&gt;\n\n&lt;?php get_sidebar(); ?&gt;&lt;?php get_footer(); ?&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6b65\u9aa4\u56db\uff1a\u521b\u5efa\u95ee\u7b54\u63d0\u4ea4\u548c\u663e\u793a\u8868\u5355<br \/>\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u524d\u7aef\u8868\u5355\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u8be5\u8868\u5355\u63d0\u4ea4\u95ee\u9898\u548c\u7b54\u6848\uff0c\u5e76\u5c06\u5176\u4fdd\u5b58\u5230\u6570\u636e\u5e93\u4e2d\u3002\u7136\u540e\uff0c\u6211\u4eec\u9700\u8981\u5728\u6a21\u677f\u4e2d\u663e\u793a\u8fd9\u4e9b\u95ee\u9898\u548c\u7b54\u6848\u3002<\/p>\n<pre>function question_form_shortcode() {\n  ob_start(); ?&amp;gt;\n\n  <\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    Question Title  Question Content  Your Answer     $question_title, &#8216;post_content&#8217; =&gt; $question_content, &#8216;post_type&#8217; =&gt; &#8216;question&#8217;, &#8216;post_status&#8217; =&gt; &#8216;publish&#8217; )); $answers = get_post_meta($question_id, &#8216;answers&#8217;, true); $answers[] = $answer_content; update_post_meta($question_id, &#8216;answers&#8217;, $answers); } } add_action(&#8216;init&#8217;, &#8216;save_question_and_answer&#8217;); <\/p>\n<p>\u7ed3\u8bba\uff1a<br \/>\u901a\u8fc7\u672c\u6587\u7684\u6307\u5bfc\uff0c\u60a8\u53ef\u4ee5\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u95ee\u7b54\u7cfb\u7edf\u7684WordPress\u63d2\u4ef6\u3002\u8fd9\u4e2a\u63d2\u4ef6\u53ef\u4ee5\u5e2e\u52a9\u60a8\u65b9\u4fbf\u5730\u521b\u5efa\u4e00\u4e2a\u95ee\u7b54\u5e73\u53f0\uff0c\u589e\u52a0\u4e92\u52a8\u6027\u548c\u5438\u5f15\u529b\u3002\u60a8\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u6dfb\u52a0\u5176\u4ed6\u529f\u80fd\u548c\u5b9a\u5236\u6837\u5f0f\uff0c\u4ee5\u6ee1\u8db3\u60a8\u7684\u7528\u6237\u548c\u7f51\u7ad9\u7684\u9700\u6c42\u3002\u795d\u60a8\u5f00\u53d1\u6210\u529f\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u95ee\u7b54\u7cfb\u7edf\u7684WordPress\u63d2\u4ef6\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>\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u95ee\u7b54\u7cfb\u7edf\u7684WordPress\u63d2\u4ef6 \u7b80\u4ecb\uff1a\u5728\u73b0\u4ee3\u4e92\u8054\u7f51\u65f6\u4ee3\uff0c\u95ee\u7b54\u7f51\u7ad9\u53d8\u5f97\u8d8a\u6765\u8d8a\u53d7\u6b22\u8fce\u3002\u4e3a\u4e86\u6ee1\u8db3\u7528\u6237\u5bf9\u95ee\u9898\u548c\u7b54\u6848\u7684\u9700\u6c42\uff0c\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u95ee\u7b54\u7cfb\u7edf\u7684WordPress\u63d2\u4ef6\u3002\u901a\u8fc7\u8fd9\u4e2a\u63d2\u4ef6\uff0c\u60a8\u53ef\u4ee5\u65b9\u4fbf\u5730\u521b\u5efa\u4e00\u4e2a\u95ee\u7b54\u5e73\u53f0\uff0c\u4f7f\u60a8\u7684\u7f51\u7ad9\u66f4\u52a0\u4ea4\u4e92\u548c\u5177\u6709\u5438\u5f15\u529b\u3002 \u6b65\u9aa4\u4e00\uff1a\u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u8d44\u6599\u7c7b\u578b\uff08Post Type\uff09\u5728WordPress\u4e2d\uff0c\u81ea\u5b9a\u4e49\u7684\u8d44\u6599\u7c7b\u578b\u662f\u4e00\u79cd\u53ef\u4ee5\u6269\u5c55\u9ed8\u8ba4\u7684\u6587\u7ae0\u548c\u9875\u9762\u7684\u529f\u80fd\u3002\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cQuestion\u201d\u7684\u81ea\u5b9a\u4e49\u8d44\u6599\u7c7b\u578b\u3002 function create_question_post_type() { $labels = array( &#8216;name&#8217; =&amp;gt; &#8216;Questions&#8217;, &#8216;singular_name&#8217; =&amp;gt; &#8216;Question&#8217;, &#8216;add_new&#8217; =&amp;gt; &#8216;Add New&#8217;, &#8216;add_new_item&#8217; =&amp;gt; &#8216;Add New Question&#8217;, &#8216;edit_item&#8217; =&amp;gt; &#8216;Edit Question&#8217;, &#8216;new_item&#8217; =&amp;gt; &#8216;New Question&#8217;, &#8216;view_item&#8217; =&amp;gt; &#8216;View Question&#8217;, &#8216;search_items&#8217; =&amp;gt; &#8216;Search Questions&#8217;, &#8216;not_found&#8217; =&amp;gt; &#8216;No questions found&#8217;, &#8216;not_found_in_trash&#8217; =&amp;gt; &#8216;No questions found in trash&#8217;, &#8216;parent_item_colon&#8217; =&amp;gt; [&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-32829","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32829","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=32829"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32829\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32829"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32829"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}