{"id":1207,"date":"2010-02-12T13:46:01","date_gmt":"2010-02-12T05:46:01","guid":{"rendered":"http:\/\/nan.im\/blog\/?p=1207"},"modified":"2010-02-12T13:46:01","modified_gmt":"2010-02-12T05:46:01","slug":"drupal-%e4%b8%ad%e5%9f%ba%e4%ba%8e%e5%88%86%e7%b1%bb-taxonomy-%e5%ae%9e%e7%8e%b0%e7%9b%b8%e5%85%b3%e6%96%87%e7%ab%a0-related-post","status":"publish","type":"post","link":"https:\/\/nan.im\/blog\/1207","title":{"rendered":"\u3010Drupal\u3011\u57fa\u4e8e\u5206\u7c7b taxonomy \u5b9e\u73b0\u76f8\u5173\u6587\u7ae0 Related Post"},"content":{"rendered":"<p>\u5bf9\u4e8e\u504f\u5185\u5bb9\u578b\u7ad9\u70b9\u6765\u8bf4\uff0c\u76f8\u5173\u6587\u7ae0\uff08Related Post\uff09\u6210\u4e3a\u7559\u4f4f\u6e38\u5ba2\u4ece\u800c\u964d\u4f4e\u8bbf\u5ba2\u8df3\u51fa\u7387\u7684\u91cd\u8981\u624b\u6bb5\uff0c\u867d\u7136\u5728 Drupal \u4e2d\u9ed8\u8ba4\u662f\u6ca1\u6709\u6b64\u7c7b\u529f\u80fd\u4f46 Drupal \u672c\u8eab\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u5f88\u591a\u4e30\u5bcc\u7684 API \u63a5\u53e3\u4f7f\u6211\u4eec\u53ef\u4ee5\u501f\u52a9\u5206\u7c7b taxonomy \u7684\u4e00\u4e9b\u63a5\u53e3\u5f88\u5bb9\u6613\u7684\u901a\u8fc7\u4fee\u6539\u4e3b\u9898\u6a21\u677f Theme \u4e3a Drupal \u7ad9\u70b9\u6dfb\u52a0\u8bf8\u5982 \u76f8\u5173\u6587\u7ae0 \u7c7b\u4f3c\u6587\u7ae0 \u63a8\u8350\u5185\u5bb9 \u7b49\u529f\u80fd\u2026\u2026<!--more--><\/p>\n<p>\u4ee3\u7801\u53ef\u653e\u5165\u76f8\u5e94\u8282\u70b9\u7c7b\u578b\u7684 node.tpl.php \u5177\u4f53\u5982\u4e0b\uff1a<\/p>\n<pre lang=\"php\" line=\"1\">\n\n$title = 'Related Post :';\n$items = $atids = array();\n\nforeach($node->taxonomy as $term){ $atids[] = $term->tid; }\n\n$datas = taxonomy_select_nodes($atids, 'or');\nwhile ($data = db_fetch_object($datas)){\n\t$items[] = l($data->title, 'node\/'.$data->nid);\n}\n\necho theme('item_list', $items, $title, $type = 'ul');\n\n<\/pre>\n<p>\u4ee3\u7801\u975e\u5e38\u7b80\u5355\u9996\u5148\u662f\u83b7\u53d6\u8be5\u8282\u70b9\u6240\u6709\u672f\u8bed\u6807\u7b7e term \u7684 tid \u7136\u540e\u4f7f\u7528 drupal \u63d0\u4f9b\u7684 <a href=\"http:\/\/api.drupal.org\/api\/function\/taxonomy_select_nodes\">taxonomy_select_nodes<\/a> \u51fd\u6570\u76f4\u63a5\u53d6\u5f97\u7ad9\u70b9\u5185\u6240\u6709\u542b\u6709\u76f8\u540c\u672f\u8bed\u7684 node \u8282\u70b9\u91cd\u7ec4\u4e3a\u4e00\u4e2a\u6570\u7ec4\u4ea4\u7ed9 item_list \u4e3b\u9898\u51fd\u6570\u8f93\u51fa\u5373\u53ef\u3002<\/p>\n<p>\u65b9\u6cd5\u6bd4\u8f83\u7b80\u5355\u6240\u6709\u7b97\u6cd5\u80af\u5b9a\u4e5f\u4f1a\u6bd4\u8f83\u5f31\u667a\uff0c\u5355\u7eaf\u7684\u6839\u636e\u672f\u8bed\u6807\u7b7e\uff08term\uff09\u6765\u63a8\u8350\u76f8\u5173\u6587\u7ae0\u4f1a\u5bfc\u81f4\u63a8\u8350\u5185\u5bb9\u4e0d\u51c6\u786e\uff0c\u5982\u679c\u80fd\u4f7f\u7528\u66f4\u9ad8\u7ea7\u7684\u7b97\u6cd5\u5f53\u7136\u6700\u597d\u3002\u8fd8\u6709\u5c31\u662f\u4e0d\u80fd\u81ea\u7531\u9009\u62e9\u53c2\u4e0e\u76f8\u5173\u6587\u7ae0\u7684\u8282\u70b9\u7c7b\u578b\uff08node type\uff09\u4f60\u80af\u5b9a\u4e0d\u60f3\u6240\u6709\u8282\u70b9\u7c7b\u578b\u53c2\u4e0e\u76f8\u5173\u6587\u7ae0\uff0c\u6211\u7684\u505a\u6cd5\u662f\u5728\u4e3a $items[] \u8d4b\u503c\u4e4b\u524d\u7528 node_load \u8bfb\u53d6 nodeType \u5e76\u5224\u65ad\uff0c\u4f46\u8fd9\u540c\u65f6\u4e5f\u6d88\u8017\u5927\u91cf\u8d44\u6e90\u548c\u727a\u7272\u7ad9\u70b9\u6027\u80fd\u672c\u8eab taxonomy_select_nodes \u5c31\u4e0d\u662f\u7701\u6cb9\u7684\u51fd\u6570\uff0c\u6240\u4ee5\u6211\u4e5f\u5728\u5f00\u7bc7\u5c31\u8868\u793a\u8be5\u65b9\u6cd5\u66f4\u9002\u7528\u4e8e\u504f\u5185\u5bb9\u578b\u7ad9\u70b9\uff0c\u8be5\u7c7b\u7ad9\u70b9\u591a\u4e3a\u6e38\u5ba2\u8bbf\u5ba2\u7528\u6237\u53ef\u4ee5\u5f00\u542f\u7ad9\u70b9\u7f13\u5b58\u8282\u70b9\u4e0d\u7528\u6bcf\u6b21\u90fd\u6267\u884c\u591a\u6b21\u67e5\u8be2\uff0c\u5bf9\u4e8e\u975e\u7f13\u5b58\u7ad9\u70b9\u8be5\u65b9\u6cd5\u5e76\u4e0d\u63a8\u8350\u3002<\/p>\n<p>\u5f53\u7136\u6211\u89c9\u5f97\u6700\u597d\u7684\u65b9\u6cd5\u8fd8\u662f\u4f7f\u7528\u66f4\u667a\u80fd\u9ad8\u7ea7\u7684\u7b97\u6cd5\u6839\u636e\u8282\u70b9\u6807\u9898\u3001\u672f\u8bed\u3001\u5185\u5bb9\u7b49\u53c2\u6570\u5e76\u65bd\u4ee5\u4e0d\u540c\u7684\u6743\u91cd\uff0c\u76f4\u63a5\u8bfb\u53d6\u6570\u636e\u5e93\u751f\u6210\u76f8\u5173\u6587\u7ae0\u4f1a\u597d\u7684\u591a\uff0c\u7c7b\u4f3c WordPress \u4e0a\u7684 <a href=\"http:\/\/wordpress.org\/extend\/plugins\/yet-another-related-posts-plugin\/\">YARPP<\/a> \u6a21\u5757\u5c31\u505a\u7684\u975e\u5e38\u667a\u80fd\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5bf9\u4e8e\u504f\u5185\u5bb9\u578b\u7ad9\u70b9\u6765\u8bf4\uff0c\u76f8\u5173\u6587\u7ae0\uff08Related Post\uff09\u6210\u4e3a\u7559\u4f4f\u6e38\u5ba2\u4ece\u800c\u964d\u4f4e\u8bbf\u5ba2\u8df3\u51fa\u7387\u7684\u91cd\u8981\u624b\u6bb5\uff0c\u867d\u7136\u5728 D [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[20,24,31,120,76],"class_list":["post-1207","post","type-post","status-publish","format-standard","hentry","category-tech","tag-code","tag-develop","tag-drupal","tag-php","tag-theme"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6}},"_links":{"self":[{"href":"https:\/\/nan.im\/blog\/wp-json\/wp\/v2\/posts\/1207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nan.im\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nan.im\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nan.im\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nan.im\/blog\/wp-json\/wp\/v2\/comments?post=1207"}],"version-history":[{"count":0,"href":"https:\/\/nan.im\/blog\/wp-json\/wp\/v2\/posts\/1207\/revisions"}],"wp:attachment":[{"href":"https:\/\/nan.im\/blog\/wp-json\/wp\/v2\/media?parent=1207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nan.im\/blog\/wp-json\/wp\/v2\/categories?post=1207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nan.im\/blog\/wp-json\/wp\/v2\/tags?post=1207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}