{"id":4861,"date":"2019-02-08T02:57:27","date_gmt":"2019-02-07T18:57:27","guid":{"rendered":"https:\/\/www.npc.ink\/4861.html"},"modified":"2019-03-29T11:23:57","modified_gmt":"2019-03-29T03:23:57","slug":"wordpress%e5%87%bd%e6%95%b0%ef%bc%9awp_tag_cloud%ef%bc%88%e6%a0%87%e7%ad%be%e4%ba%91%ef%bc%89-2","status":"publish","type":"post","link":"https:\/\/www.npc.ink\/4861.html","title":{"rendered":"WordPress\u51fd\u6570\uff1awp_tag_cloud\uff08\u6807\u7b7e\u4e91\uff09"},"content":{"rendered":"
\u6765\u6e90\u4e8e\uff1a<\/strong><\/p>\n https:\/\/www.wpdaxue.com\/wp_tag_cloud.html<\/p><\/blockquote>\n \u51fd\u6570\u5b98\u65b9\u6587\u6863\uff1a<\/strong><\/p>\n wp_tag_cloud() \u51fd\u6570\u7684\u4f5c\u7528\u662f\u7528\u6765\u6807\u7b7e\u4e91\u7684\uff0c\u53ef\u4ee5\u6839\u636e\u6bcf\u4e2a\u6807\u7b7e\u6240\u5173\u8054\u7684\u6587\u7ae0\u6b21\u6570\u6765\u5b9a\u4e49\u5b57\u4f53\u5927\u5c0f\u3001\u6807\u7b7e\u6392\u5e8f\u7b49\u5c5e\u6027\u3002\u4ece 2.8 \u7248\u672c\u5f00\u59cb\uff0c\u6dfb\u52a0\u4e86 \u5206\u7c7b\u6cd5\uff08taxonomy\uff09\u53c2\u6570\uff0c\u8fd9\u5c31\u610f\u5473\u7740\uff0c\u9664\u4e86 \u6807\u7b7e\uff08tags\uff09\u4ee5\u5916\uff0c\u8fd8\u53ef\u4ee5\u5c06 \u5206\u7c7b\uff08Categories\uff09 \u6216\u5176\u4ed6 \u81ea\u5b9a\u4e49\u5206\u7c7b\u6cd5\uff08Custom Taxonomies\uff09\u4f5c\u4e3a\u201c\u4e91\u201d\u663e\u793a\u3002<\/p>\n \u7528\u6cd5<\/p>\n \u9ed8\u8ba4\u7528\u6cd5<\/p>\n \u6ce8\uff1a child_of \u4e0d\u662f\u4e00\u4e2a\u76f4\u63a5\u7684 wp_tag_cloud \u6570\u7ec4\u7684\u952e\uff08Key\uff09\uff0c\u4f46\u7531\u4e8e\u8fd9\u4e2a\u51fd\u6570\u4f7f\u7528 wp_parse_args() \u548c get_terms() \uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7 get_terms() \u4f7f\u7528\u6240\u6709\u7684\u6570\u7ec4\u952e\u3002<\/p>\n \u9ed8\u8ba4\u60c5\u51b5\u4e0b\u7684\u8f93\u51fa\u5185\u5bb9\uff1a<\/p>\n smallest<\/strong><\/p>\n \uff08\u6574\u6570\uff09\uff08\u53ef\u9009\uff09\u4f7f\u7528\u6b21\u6570\u6700\u5c11\u7684\u6807\u7b7e\u7684\u5b57\u53f7\u5927\u5c0f\uff08\u5355\u4f4d\u7531unit\u53c2\u6570\u51b3\u5b9a\uff09<\/p>\n \u9ed8\u8ba4\u503c\uff1a8<\/p>\n largest<\/strong><\/p>\n \uff08\u6574\u6570\uff09\uff08\u53ef\u9009\uff09\u4f7f\u7528\u6b21\u6570\u6700\u591a\u7684\u6807\u7b7e\u7684\u5b57\u53f7\u5927\u5c0f\uff08\u5355\u4f4d\u7531unit\u53c2\u6570\u51b3\u5b9a\uff09<\/p>\n \u9ed8\u8ba4\u503c\uff1a22<\/p>\n unit<\/strong><\/p>\n \uff08\u5b57\u7b26\u4e32\uff09\uff08\u53ef\u9009\uff09\u5bf9smallest<\/strong>\u4e0elargest<\/strong>\u7684\u503c\u7684\u6d4b\u91cf\u5355\u4f4d\u3002\u53ef\u4ee5\u662f\u4efb\u4f55CSS\u957f\u5ea6\u5355\u4f4d\uff0c\u5982pt, px, em, %\u3002<\/p>\n \u9ed8\u8ba4\u503c\uff1a\u2019pt\u2019<\/p>\n number<\/strong><\/p>\n \uff08\u6574\u6570\uff09\uff08\u53ef\u9009\uff09\u663e\u793a\u5728\u4e91\u4e2d\u7684\u5b9e\u9645\u6807\u7b7e\u6570\u3002\uff08\u503c\u4e3a\u20190\u2019\u65f6\u663e\u793a\u6240\u6709\u6807\u7b7e\uff09<\/p>\n \u9ed8\u8ba4\u503c\uff1a45<\/p>\n format<\/strong><\/p>\n \uff08\u5b57\u7b26\u4e32\uff09\uff08\u53ef\u9009\uff09\u6240\u663e\u793a\u7684\u4e91\u7684\u683c\u5f0f\u3002<\/p>\n separator<\/strong><\/p>\n \uff08\u5b57\u7b26\u4e32\uff09\uff08\u53ef\u9009\uff09\u6807\u7b7e\u4e4b\u95f4\u7684\u6587\u672c\/\u7a7a\u683c\u3002<\/p>\n \u9ed8\u8ba4\u503c\uff1a\u2019\\n\u2019 \uff08\u7a7a\u683c\uff09<\/p>\n orderby<\/strong><\/p>\n \uff08\u5b57\u7b26\u4e32\uff09\uff08\u53ef\u9009\uff09\u6807\u7b7e\u7684\u6392\u5217\u4f9d\u636e\u3002\u6709\u6548\u503c\u5305\u62ec\uff1a<\/p>\n order<\/strong><\/p>\n \uff08\u5b57\u7b26\u4e32\uff09\uff08\u53ef\u9009\uff09\u6392\u5217\u987a\u5e8f\uff08\u5347\u5e8f\u6216\u964d\u5e8f\uff09\u3002\u6709\u6548\u503c\u5305\u62ec\uff08\u5fc5\u987b\u5927\u5199\uff09\uff1a<\/p>\n exclude<\/strong><\/p>\n \uff08\u5b57\u7b26\u4e32\uff09\uff08\u53ef\u9009\uff09\u5c06\u8981\u88ab\u6392\u9664\u7684\u6807\u7b7e\uff08term_id\uff09\u7684ID\uff0c\u5404ID\u7528\u9017\u53f7\u9694\u5f00\u3002\u5982 \u2018exclude=5,27\u2019\u8868\u793a\u4e0d\u663e\u793aterm_id\u4e3a5\u621627\u7684\u6807\u7b7e\u3002\u9ed8\u8ba4\u503c\u4e3a\u4e0d\u6392\u9664\u4efb\u4f55\u6807\u7b7e\u3002<\/p>\n include<\/strong><\/p>\n \uff08\u5b57\u7b26\u4e32\uff09\uff08\u53ef\u9009\uff09\u8981\u5305\u542b\u7684\u6807\u7b7e\uff08term_id\uff09\u5217\u8868\uff0c\u5404ID\u7528\u9017\u53f7\u9694\u5f00\u3002\u4f8b\u5982\uff0c \u2018include=5,27\u2019 \u8868\u793a\u53ea\u663e\u793aterm_id\u4e3a5\u621627\u7684\u6807\u7b7e\u3002\u9ed8\u8ba4\u4e3a\u5305\u542b\u6240\u6709\u94fe\u63a5\u3002<\/p>\n topic_count_text_callback<\/strong><\/p>\n \uff08\u5b57\u7b26\u4e32\uff09\uff08\u53ef\u9009\uff09\u7ed9\u51fa\u6807\u7b7e\u6240\u5173\u8054\u7684\u6587\u7ae0\u6570\uff0c\u8fd4\u56de\u6807\u7b7e\u94fe\u63a5\u7684\u7528\u4e8e tooltip \u7684\u6587\u672c\u3002<\/p>\n \u9ed8\u8ba4\u503c\uff1a default_topic_count_text<\/p>\n link<\/strong><\/p>\n \uff08\u5b57\u7b26\u4e32\uff09\uff08\u53ef\u9009\uff09\u8bbe\u7f6e\u94fe\u63a5\uff0c\u5141\u8bb8\u7f16\u8f91\u67d0\u4e2a\u6307\u5b9a\u6807\u7b7e\u3002\u6709\u6548\u503c\u5305\u62ec\uff1a<\/p>\n taxonomy<\/strong><\/p>\n \uff08\u5b57\u7b26\u4e32\uff09\uff08\u53ef\u9009\uff09\u7528\u4ee5\u751f\u6210\u4e91\u7684\u5206\u7c7b\u6cd5\u3002<\/p>\n echo<\/strong><\/p>\n \uff08\u5e03\u5c14\u578b\uff09\uff08\u53ef\u9009\uff09\u663e\u793a\u7ed3\u679c\uff0c\u6216\u5c06\u7ed3\u679c\u4fdd\u7559\u5728\u53d8\u91cf\u4e2d\u3002\u9ed8\u8ba4\u503c\u4e3atrue\uff08\u663e\u793a\u6807\u7b7e\u4e91\uff09\u3002\u6709\u6548\u503c\u5305\u62ec\uff1a<\/p>\n \u663e\u793a\u6807\u9898\u4e3aPopular Tags\u7684\u4e91<\/p>\n \u9650\u5236\u6807\u7b7e\u5927\u5c0f\u4e14\u4ee5\u4f7f\u7528\u6b21\u6570\u800c\u975e\u540d\u79f0\u6392\u5217\u6807\u7b7e\u7684\u4e91<\/p>\n \u5728\u53d8\u91cf$tag\u4e2d\u5305\u542b\u6807\u7b7e\u4e91\uff0c\u4ee5\u7528\u5728\u5176\u5b83PHP\u4ee3\u7801\u4e2d<\/p>\n \u4f7f\u7528\u5206\u7c7b\u6cd5\uff08taxonomy\uff09\u53c2\u6570\u5b9a\u4e49\u663e\u793a\u5206\u7c7b\u4e91<\/p>\n \u4f7f\u7528\u5206\u7c7b\u6cd5\u6570\u7ec4\u5c06\u5206\u7c7b\u548c\u6807\u7b7e\u663e\u793a\u4e3a\u4e91<\/p>\n \u4f7f\u7528 topic_count_text_callback \u53c2\u6570\u4f20\u9012\u4e00\u4e2a\u65b0\u7684\u8fd4\u56de\u51fd\u6570\u3002\u539f\u59cb\u51fd\u6570 default_topic_count_text() \u4f4d\u4e8e \/wp-includes\/category-template.php \u3002\u8fd9\u4e2a\u4f8b\u5b50\u4f7f\u7528\u201cpictures\u201d\u66ff\u6362\u9ed8\u8ba4\u7684\u201ctopics\u201d\uff1a<\/p>\n \u4ece 2.3 \u7248\u672c\u5f00\u59cb\uff0c\u6807\u7b7e\u4e91\u53ef\u4ee5\u5236\u4f5c\u6210\u4e00\u4e2a\u6807\u7b7e\u5b58\u6863\u9875\u9762\u3002\u8fd9\u5c31\u610f\u5473\u7740\uff0c\u7528\u6237\u53ef\u4ee5\u70b9\u51fb\u67d0\u4e2a\u6807\u7b7e\uff0c\u7136\u540e\u67e5\u770b\u5230\u8be5\u4f7f\u7528\u8be5\u6807\u7b7e\u7684\u6240\u6709\u6587\u7ae0\u3002\u6839\u636e \u6a21\u677f\u5c42\u7ea7\uff08Template_Hierarchy\uff09\uff0c\u5982\u679ctag.php\u6a21\u677f\u4e0d\u5b58\u5728\uff0c\u90a3\u4e48\u5c31\u4f7f\u7528archives.php\u6a21\u677f\u3002\u901a\u8fc7tag,php\u6a21\u677f\u4f60\u53ef\u4ee5\u81ea\u5b9a\u4e49\u6807\u7b7e\u5b58\u6863\u7d22\u5f15\u7684\u6837\u5f0f\uff0c\u4e3a\u65b9\u4fbf\u5bfc\u822a\uff0c\u6a21\u677f\u4f1a\u5728\u6700\u4e0a\u65b9\u5305\u542b\u6807\u7b7e\u4e91\u3002<\/p>\n \u8981\u5c06\u6807\u7b7e\u4e91\u663e\u793a\u5728\u6a21\u677f\u4e0a\u65b9\uff0c\u4f60\u9700\u8981\u5c06\u4e00\u4e2a\u65b0\u6a21\u677f\u6dfb\u52a0\u5230\u4e3b\u9898\u6587\u4ef6\u4e2d\u3002\u6a21\u677f\u3001\u6a21\u677f\u5c42\u7ea7 \u4e2d\u6709\u76f8\u5173\u4ecb\u7ecd\u3002\u57fa\u7840\u6b65\u9aa4\u5305\u62ec\uff1a<\/p>\n 1. \u7528\u4e0b\u9762\u7684\u5185\u5bb9\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\uff0c\u547d\u540d\u4e3atag.php<\/p>\n 2. \u5c06\u65b0\u6587\u4ef6\u4e0a\u4f20\u5230\u4e3b\u9898\u76ee\u5f55\u4e0b<\/p>\n 3. \u5982\u679c\u4f60\u5e0c\u671b\u5728\u9875\u9762\u5bfc\u822a\u4e2d\u52a0\u5165\u4e00\u4e2a\u6307\u5411\u6807\u7b7e\u7d22\u5f15\u7684\u94fe\u63a5\uff0c\u53ef\u8fdb\u884c\u7b2c\u4e09\u6b65\u9aa4\uff0c\u5426\u5219\u70b9\u51fb\u67d0\u4e2a\u6807\u7b7e\u65f6\u4f1a\u4f7f\u7528\u65b0\u6a21\u677f\u3002<\/p>\n \u5bf9\u7b2c\u4e09\u6b65\u7684\u8fdb\u4e00\u6b65\u9610\u8ff0\uff1a<\/p>\n WordPress\u53ef\u4e3a\u4e0d\u540c\u9875\u9762\u4f7f\u7528\u4e0d\u540c\u9875\u9762\u6a21\u677f\u3002\u5728 \u9875\u9762>\u6dfb\u52a0\u65b0\u9875\u9762 \u754c\u9762\u7684\u6700\u4e0b\u65b9\uff08\u6216\u662f\u4fa7\u8fb9\u680f\uff0c\u53d6\u51b3\u4e8e\u4f60\u5b89\u88c5\u7684WordPress\u7248\u672c\uff09\u6709\u4e00\u4e2a\u540d\u4e3a\u201c\u9875\u9762\u6a21\u677f\u201d\u7684\u4e0b\u62c9\u5f0f\u83dc\u5355\u3002\u4f60\u53ef\u4ee5\u5728\u8fd9\u91cc\u9009\u62e9\u663e\u793a\u67d0\u4e2a\u9875\u9762\u6240\u7528\u7684\u6a21\u677f\u3002<\/p>\n \u6ce8\u610f\uff1a\u6a21\u677f\u8fd8\u6ca1\u6709\u6dfb\u52a0\u6837\u5f0f\u3002\u901a\u8fc7\u67e5\u770bsingle.php\u4e3b\u9898\u6587\u4ef6\u53ef\u4ee5\u4e86\u89e3\u4f60\u7684\u4e3b\u9898\u6240\u7528\u7684\u7ed3\u6784\u3002<\/p>\n wp_tag_cloud() \u4f4d\u4e8e wp-includes\/category-template.php<\/p>\n","protected":false},"excerpt":{"rendered":" \u5236\u4f5c\u6807\u7b7e\u4e91\u76f8\u5173\u7684\u529f\u80fd\u65f6\uff0c\u53ef\u4ee5\u53c2\u8003\u53c2\u8003<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[204,263],"collection":[],"class_list":["post-4861","post","type-post","status-publish","format-standard","hentry","tag-wp-development","tag-hs"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/posts\/4861"}],"collection":[{"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/comments?post=4861"}],"version-history":[{"count":0,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/posts\/4861\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/media?parent=4861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/categories?post=4861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/tags?post=4861"},{"taxonomy":"collection","embeddable":true,"href":"https:\/\/www.npc.ink\/wp-json\/wp\/v2\/collection?post=4861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\u8bf4\u660e<\/h2>\n
<?php<\/span> wp_tag_cloud( $args ); ?><\/span>\n<\/pre>\n
<?php<\/span> $args = array<\/span>(\n'smallest'<\/span> => 8<\/span>, \n'largest'<\/span> => 22<\/span>,\n'unit'<\/span> => 'pt'<\/span>, \n'number'<\/span> => 45<\/span>, \n'format'<\/span> => 'flat'<\/span>,\n'separator'<\/span> => \"\\n\"<\/span>,\n'orderby'<\/span> => 'name'<\/span>, \n'order'<\/span> => 'ASC'<\/span>,\n'exclude'<\/span> => null<\/span>, \n'include'<\/span> => null<\/span>, \n'topic_count_text_callback'<\/span> => default_topic_count_text,\n'link'<\/span> => 'view'<\/span>, \n'taxonomy'<\/span> => 'post_tag'<\/span>, \n'echo'<\/span> => true<\/span>,\n'child_of'<\/span> => null<\/span>(see Note!)\n); ?><\/span>\n<\/pre>\n
\n
\u53c2\u6570<\/h2>\n
\n
\n
\n
\n
\n
\n
\u4f8b\u5b50<\/h2>\n
<?php<\/span> if<\/span> ( function_exists('wp_tag_cloud'<\/span>) ) : ?><\/span>\n \n<h2<\/span>><\/span>Popular Tags<\/h2<\/span>><\/span>\n<ul<\/span>><\/span>\n<li<\/span>><\/span><?php<\/span> wp_tag_cloud('smallest=8&largest=22'<\/span>); ?><\/span><\/li<\/span>><\/span>\n<\/ul<\/span>><\/span>\n \n<?php<\/span> endif<\/span>; ?><\/span>\n<\/pre>\n
<?php<\/span> wp_tag_cloud('smallest=15&largest=40&number=50&orderby=count'<\/span>); ?><\/span>\n<\/pre>\n
\u4ee5\u6570\u7ec4\u5f62\u5f0f\u8fd4\u56de\u4e91\uff0c\u4f46\u4e0d\u663e\u793a<\/h3>\n
<?php<\/span> $tag = wp_tag_cloud('format=array'<\/span> );?><\/span>\n<\/pre>\n
\u663e\u793a\u5206\u7c7b\u4e91<\/h3>\n
<?php<\/span> \nwp_tag_cloud( array<\/span>( 'taxonomy'<\/span> => 'category'<\/span> ) ); \n?><\/span>\n<\/pre>\n
\u663e\u793a \u5206\u7c7b \u548c \u6807\u7b7e \u4e91<\/h3>\n
<?php<\/span> \n $args = array<\/span>('taxonomy'<\/span> => array<\/span>('post_tag'<\/span>,'category'<\/span>), \n ); \n \n wp_tag_cloud($args);\n?><\/span>\n<\/pre>\n
\u66f4\u6539\u4e91\u94fe\u63a5\u7684\u6807\u9898\u6587\u672c<\/h3>\n
<?php<\/span> \nwp_tag_cloud( array<\/span>( 'topic_count_text_callback'<\/span> => 'my_tag_text_callback'<\/span> ) ); \n \nfunction<\/span> my_tag_text_callback<\/span>( $count )<\/span> <\/span>{return<\/span> sprintf( _n('%s picture'<\/span>, '%s pictures'<\/span>, $count), number_format_i18n( $count ) );\n}\n?><\/span>\n<\/pre>\n
\u521b\u5efa\u6807\u7b7e\u5b58\u6863\u9875\u9762<\/h3>\n
\n
<?php<\/span> \/*\nTemplate Name: Tag Archive\n*\/<\/span> ?><\/span>\n<div<\/span>><\/span>\n<?php<\/span> get_header(); ?><\/span>\n<h2<\/span>><\/span>Tag Archive<\/h2<\/span>><\/span>\n<?php<\/span> wp_tag_cloud(''<\/span>); ?><\/span>\n\t<div<\/span> class<\/span>=\"navigation\"<\/span>><\/span>\n<div<\/span> class<\/span>=\"alignleft\"<\/span>><\/span><?php<\/span> next_posts_link('\u00ab Older Entries'<\/span>) ?><\/span><\/div<\/span>><\/span>\n<div<\/span> class<\/span>=\"alignright\"<\/span>><\/span><?php<\/span> previous_posts_link('Newer Entries \u00bb'<\/span>) ?><\/span><\/div<\/span>><\/span>\n\t<\/div<\/span>><\/span>\n<?php<\/span> if<\/span> (have_posts()) : ?><\/span>\n\t\t<?php<\/span> while<\/span> (have_posts()) : the_post(); ?><\/span>\n\t\t<h2<\/span>><a<\/span> href<\/span>=\"<?php the_permalink() ?>\"<\/span> rel<\/span>=\"bookmark\"<\/span> title<\/span>=\"Permanent Link to <?php the_title(); ?>\"<\/span>><\/span><?php<\/span> the_title(); ?><\/span><\/a<\/span>><\/h2<\/span>><\/span>\n\t<div<\/span> class<\/span>=\"entry\"<\/span>><\/span>\n\t<?php<\/span> the_content('Read the rest of this entry \u00bb'<\/span>); ?><\/span>\n\t<\/div<\/span>><\/span>\n \n\t<?php<\/span> endwhile<\/span>; ?><\/span>\n\t<?php<\/span> endif<\/span>; ?><\/span>\n<\/div<\/span>><\/span>\n<?php<\/span> get_footer(); ?><\/span>\n<\/pre>\n
\u51fd\u6570\u5386\u53f2<\/h2>\n
\n
\u6e90\u6587\u4ef6<\/h2>\n