{"id":32870,"date":"2024-11-25T15:14:14","date_gmt":"2024-11-25T07:14:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32870\/"},"modified":"2024-11-25T15:14:14","modified_gmt":"2024-11-25T07:14:14","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%e5%85%b3%e7%b3%bb%e5%9b%be%e7%9a%84wordpress%e6%8f%92%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32870\/","title":{"rendered":"\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5173\u7cfb\u56fe\u7684WordPress\u63d2\u4ef6"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169391053921458.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5173\u7cfb\u56fe\u7684WordPress\u63d2\u4ef6\u63d2\u56fe\" alt=\"\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5173\u7cfb\u56fe\u7684WordPress\u63d2\u4ef6\u63d2\u56fe\" \/><\/p>\n<p>\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5173\u7cfb\u56fe\u7684WordPress\u63d2\u4ef6<\/p>\n<p>\u968f\u7740\u4fe1\u606f\u65f6\u4ee3\u7684\u53d1\u5c55\uff0c\u6211\u4eec\u751f\u6d3b\u4e2d\u4ea7\u751f\u7684\u6570\u636e\u8d8a\u6765\u8d8a\u591a\uff0c\u6570\u636e\u4e4b\u95f4\u7684\u5173\u7cfb\u4e5f\u53d8\u5f97\u8d8a\u6765\u8d8a\u590d\u6742\u3002\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3\u548c\u5448\u73b0\u6570\u636e\u4e4b\u95f4\u7684\u5173\u8054\uff0c\u5173\u7cfb\u56fe\u6210\u4e3a\u4e86\u4e00\u79cd\u91cd\u8981\u7684\u53ef\u89c6\u5316\u5de5\u5177\u3002\u800cWordPress\u4f5c\u4e3a\u5168\u7403\u6700\u6d41\u884c\u7684\u5185\u5bb9\u7ba1\u7406\u7cfb\u7edf\uff0c\u4e3a\u7f51\u7ad9\u5efa\u8bbe\u8005\u63d0\u4f9b\u4e86\u7b80\u5355\u6613\u7528\u7684\u5e73\u53f0\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5173\u7cfb\u56fe\u7684WordPress\u63d2\u4ef6\uff0c\u5e76\u9644\u5e26\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u4e86\u89e3\u5173\u7cfb\u56fe\u7684\u57fa\u672c\u7ed3\u6784\u3002\u5173\u7cfb\u56fe\u4e3b\u8981\u7531\u8282\u70b9(Node)\u548c\u8fb9(Edge)\u7ec4\u6210\u3002\u8282\u70b9\u5373\u6570\u636e\u7684\u5b9e\u4f53\uff0c\u53ef\u4ee5\u662f\u4eba\u7269\u3001\u7269\u54c1\u3001\u5730\u70b9\u7b49\uff1b\u8fb9\u5219\u8868\u793a\u8282\u70b9\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u5728\u5f00\u53d1\u63d2\u4ef6\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u5173\u7cfb\u56fe\u6570\u636e\u7684\u5b58\u50a8\u7ed3\u6784\u3002<\/p>\n<pre>\/\/ \u521b\u5efa\u8282\u70b9\u7c7b\u578b\nfunction create_node_post_type() {\n  register_post_type( 'node',\n    array(\n      'labels' =&amp;gt; array(\n        'name' =&amp;gt; __( '\u8282\u70b9' ),\n        'singular_name' =&amp;gt; __( '\u8282\u70b9' )\n      ),\n      'public' =&amp;gt; true,\n      'has_archive' =&amp;gt; true,\n      'rewrite' =&amp;gt; array('slug' =&amp;gt; 'node'),\n    )\n  );\n}\nadd_action( 'init', 'create_node_post_type' );\n\n\/\/ \u521b\u5efa\u8fb9\u7c7b\u578b\nfunction create_edge_post_type() {\n  register_post_type( 'edge',\n    array(\n      'labels' =&amp;gt; array(\n        'name' =&amp;gt; __( '\u8fb9' ),\n        'singular_name' =&amp;gt; __( '\u8fb9' )\n      ),\n      'public' =&amp;gt; true,\n      'has_archive' =&amp;gt; true,\n      'rewrite' =&amp;gt; array('slug' =&amp;gt; 'edge'),\n    )\n  );\n}\nadd_action( 'init', 'create_edge_post_type' );<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86WordPress\u63d0\u4f9b\u7684register_post_type\u51fd\u6570\u521b\u5efa\u4e86\u4e24\u4e2a\u81ea\u5b9a\u4e49\u7684\u6587\u7ae0\u7c7b\u578b\uff1anode\u548cedge\u3002\u8282\u70b9\u7c7b\u578b\u5bf9\u5e94\u5173\u7cfb\u56fe\u4e2d\u7684\u8282\u70b9\uff0c\u8fb9\u7c7b\u578b\u5bf9\u5e94\u5173\u7cfb\u56fe\u4e2d\u7684\u8fb9\u3002\u8fd9\u6837\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528WordPress\u7684\u6587\u7ae0\u529f\u80fd\u6765\u7ba1\u7406\u5173\u7cfb\u56fe\u7684\u6570\u636e\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u9875\u9762\u6765\u5c55\u793a\u5173\u7cfb\u56fe\u3002\u5728WordPress\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u81ea\u5b9a\u4e49\u9875\u9762\u6a21\u677f\u6765\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u9875\u9762\u6a21\u677f\u793a\u4f8b\uff1a<\/p>\n<pre>\/*\nTemplate Name: \u5173\u7cfb\u56fe\u6a21\u677f\n*\/\n?&amp;gt;\n\n&lt;?php get_header(); ?&gt;&lt;?php $args = array(\n  'post_type' =&gt; 'node',\n  'posts_per_page' =&amp;gt; -1\n);\n$nodes = new WP_Query($args);\n\n$args = array(\n  'post_type' =&amp;gt; 'edge',\n  'posts_per_page' =&amp;gt; -1\n);\n$edges = new WP_Query($args);\n?&amp;gt;\n\n&lt;div id=\"graph\"&gt;&lt;\/div&gt;\n\n&lt;script&gt;\n\/\/ \u5728\u8fd9\u91cc\u7f16\u5199\u751f\u6210\u5173\u7cfb\u56fe\u7684\u4ee3\u7801\n&lt;\/script&gt;&lt;?php get_footer(); ?&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u81ea\u5b9a\u4e49\u9875\u9762\u6a21\u677f\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86WP_Query\u6765\u83b7\u53d6\u6240\u6709\u7684\u8282\u70b9\u548c\u8fb9\u3002\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5728<\/p>\n<p> \u4e2d\u7f16\u5199\u751f\u6210\u5173\u7cfb\u56fe\u7684\u4ee3\u7801\u3002\u5173\u7cfb\u56fe\u7684\u751f\u6210\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e09\u65b9JavaScript\u5e93\uff0c\u5982D3.js\u3001Vis.js\u7b49\u3002 <\/p>\n<p>\u6700\u540e\uff0c\u6211\u4eec\u9700\u8981\u5c06\u63d2\u4ef6\u6253\u5305\uff0c\u5e76\u5728WordPress\u4e2d\u5b89\u88c5\u548c\u6fc0\u6d3b\u63d2\u4ef6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u63d2\u4ef6\u5165\u53e3\u6587\u4ef6\u793a\u4f8b\uff1a<\/p>\n<pre>&lt;?php \/*\nPlugin Name: \u5173\u7cfb\u56fe\u63d2\u4ef6\nPlugin URI: https:\/\/example.com\nDescription: \u81ea\u52a8\u751f\u6210\u5173\u7cfb\u56fe\u7684WordPress\u63d2\u4ef6\nVersion: 1.0\nAuthor: Your Name\nAuthor URI: https:\/\/yourwebsite.com\nLicense: GPL2\n*\/\n\n\/\/ \u914d\u7f6e\u6587\u4ef6\ndefine( 'RELATIONSHIP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );\ndefine( 'RELATIONSHIP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );\n\n\/\/ \u5728\u9875\u9762\u4e2d\u52a0\u8f7d\u811a\u672c\u548c\u6837\u5f0f\nfunction enqueue_relationship_scripts() {\n  wp_enqueue_script( 'relationship-script', RELATIONSHIP_PLUGIN_URL . 'js\/script.js', array( 'jquery' ), '1.0', true );\n}\nadd_action( 'wp_enqueue_scripts', 'enqueue_relationship_scripts' );\n\nfunction enqueue_relationship_styles() {\n  wp_enqueue_style( 'relationship-style', RELATIONSHIP_PLUGIN_URL . 'css\/style.css' );\n}\nadd_action( 'wp_enqueue_scripts', 'enqueue_relationship_styles' );\n\n\/\/ \u6ce8\u518c\u9875\u9762\u6a21\u677f\nfunction register_relationship_template( $templates ) {\n  $templates['custom-template.php'] = '\u5173\u7cfb\u56fe\u6a21\u677f';\n  return $templates;\n}\nadd_filter( 'theme_page_templates', 'register_relationship_template' );\n\n\/\/ \u6dfb\u52a0\u8bbe\u7f6e\u83dc\u5355\nfunction relationship_plugin_menu() {\n  add_options_page( '\u5173\u7cfb\u56fe\u63d2\u4ef6\u8bbe\u7f6e', '\u5173\u7cfb\u56fe\u63d2\u4ef6', 'manage_options', 'relationship-plugin', 'relationship_plugin_options' );\n}\nadd_action( 'admin_menu', 'relationship_plugin_menu' );\n\n\/\/ \u8bbe\u7f6e\u9875\u9762\u7684\u5185\u5bb9\nfunction relationship_plugin_options() {\n  if ( ! current_user_can( 'manage_options' ) ) {\n    wp_die( __( 'You do not have sufficient permissions to access this page.' ) );\n  }\n\n  \/\/ \u5728\u8fd9\u91cc\u6dfb\u52a0\u8bbe\u7f6e\u9875\u9762\u7684\u5185\u5bb9\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86WordPress\u63d0\u4f9b\u7684\u63d2\u4ef6\u5f00\u53d1\u673a\u5236\u6765\u521b\u5efa\u63d2\u4ef6\u3002\u5728\u63d2\u4ef6\u5165\u53e3\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u6ce8\u518c\u4e86\u63d2\u4ef6\u7684\u8bbe\u7f6e\u83dc\u5355\u548c\u81ea\u5b9a\u4e49\u9875\u9762\u6a21\u677f\uff0c\u5e76\u5206\u522b\u6dfb\u52a0\u4e86\u52a0\u8f7d\u811a\u672c\u548c\u6837\u5f0f\u7684\u529f\u80fd\u3002<\/p>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u6211\u4eec\u5c31\u6210\u529f\u5f00\u53d1\u4e86\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5173\u7cfb\u56fe\u7684WordPress\u63d2\u4ef6\u3002\u7528\u6237\u53ef\u4ee5\u4f7f\u7528\u7ba1\u7406\u540e\u53f0\u6765\u7ba1\u7406\u5173\u7cfb\u56fe\u7684\u6570\u636e\uff0c\u901a\u8fc7\u81ea\u5b9a\u4e49\u9875\u9762\u6a21\u677f\u6765\u5c55\u793a\u5173\u7cfb\u56fe\u3002\u540c\u65f6\uff0c\u63d2\u4ef6\u5177\u6709\u53ef\u6269\u5c55\u6027\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u6dfb\u52a0\u66f4\u591a\u529f\u80fd\u548c\u6837\u5f0f\u3002<\/p>\n<p>\u7efc\u4e0a\u6240\u8ff0\uff0c\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5173\u7cfb\u56fe\u7684WordPress\u63d2\u4ef6\u5e76\u4e0d\u590d\u6742\uff0c\u53ea\u9700\u8981\u4e86\u89e3\u5173\u7cfb\u56fe\u7684\u57fa\u672c\u7ed3\u6784\uff0c\u5e76\u4e14\u7075\u6d3b\u4f7f\u7528WordPress\u63d0\u4f9b\u7684\u529f\u80fd\u548c\u673a\u5236\u5373\u53ef\u3002\u5e0c\u671b\u672c\u6587\u80fd\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff0c\u5e76\u6fc0\u53d1\u4f60\u5f00\u53d1\u66f4\u591a\u5b9e\u7528\u7684WordPress\u63d2\u4ef6\u7684\u7075\u611f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5173\u7cfb\u56fe\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\u5173\u7cfb\u56fe\u7684WordPress\u63d2\u4ef6 \u968f\u7740\u4fe1\u606f\u65f6\u4ee3\u7684\u53d1\u5c55\uff0c\u6211\u4eec\u751f\u6d3b\u4e2d\u4ea7\u751f\u7684\u6570\u636e\u8d8a\u6765\u8d8a\u591a\uff0c\u6570\u636e\u4e4b\u95f4\u7684\u5173\u7cfb\u4e5f\u53d8\u5f97\u8d8a\u6765\u8d8a\u590d\u6742\u3002\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3\u548c\u5448\u73b0\u6570\u636e\u4e4b\u95f4\u7684\u5173\u8054\uff0c\u5173\u7cfb\u56fe\u6210\u4e3a\u4e86\u4e00\u79cd\u91cd\u8981\u7684\u53ef\u89c6\u5316\u5de5\u5177\u3002\u800cWordPress\u4f5c\u4e3a\u5168\u7403\u6700\u6d41\u884c\u7684\u5185\u5bb9\u7ba1\u7406\u7cfb\u7edf\uff0c\u4e3a\u7f51\u7ad9\u5efa\u8bbe\u8005\u63d0\u4f9b\u4e86\u7b80\u5355\u6613\u7528\u7684\u5e73\u53f0\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5f00\u53d1\u4e00\u4e2a\u81ea\u52a8\u751f\u6210\u5173\u7cfb\u56fe\u7684WordPress\u63d2\u4ef6\uff0c\u5e76\u9644\u5e26\u4ee3\u7801\u793a\u4f8b\u3002 \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u4e86\u89e3\u5173\u7cfb\u56fe\u7684\u57fa\u672c\u7ed3\u6784\u3002\u5173\u7cfb\u56fe\u4e3b\u8981\u7531\u8282\u70b9(Node)\u548c\u8fb9(Edge)\u7ec4\u6210\u3002\u8282\u70b9\u5373\u6570\u636e\u7684\u5b9e\u4f53\uff0c\u53ef\u4ee5\u662f\u4eba\u7269\u3001\u7269\u54c1\u3001\u5730\u70b9\u7b49\uff1b\u8fb9\u5219\u8868\u793a\u8282\u70b9\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u5728\u5f00\u53d1\u63d2\u4ef6\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u5173\u7cfb\u56fe\u6570\u636e\u7684\u5b58\u50a8\u7ed3\u6784\u3002 \/\/ \u521b\u5efa\u8282\u70b9\u7c7b\u578b function create_node_post_type() { register_post_type( &#8216;node&#8217;, array( &#8216;labels&#8217; =&amp;gt; array( &#8216;name&#8217; =&amp;gt; __( &#8216;\u8282\u70b9&#8217; ), &#8216;singular_name&#8217; =&amp;gt; __( &#8216;\u8282\u70b9&#8217; ) ), &#8216;public&#8217; =&amp;gt; true, &#8216;has_archive&#8217; =&amp;gt; true, &#8216;rewrite&#8217; =&amp;gt; array(&#8216;slug&#8217; =&amp;gt; &#8216;node&#8217;), ) ); } add_action( &#8216;init&#8217;, &#8216;create_node_post_type&#8217; ); \/\/ \u521b\u5efa\u8fb9\u7c7b\u578b function create_edge_post_type() { register_post_type( &#8216;edge&#8217;, array( &#8216;labels&#8217; =&amp;gt; array( &#8216;name&#8217; [&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-32870","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32870","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=32870"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32870\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}