{"id":638,"date":"2013-05-22T09:29:10","date_gmt":"2013-05-22T01:29:10","guid":{"rendered":"https:\/\/anandalue.com\/?p=638"},"modified":"2013-05-22T09:29:10","modified_gmt":"2013-05-22T01:29:10","slug":"wordpress%e6%96%87%e7%ab%a0%e9%a1%b5%e4%b8%ad%e5%a6%82%e4%bd%95%e6%b7%bb%e5%8a%a0%e7%8c%9c%e4%bd%a0%e5%96%9c%e6%ac%a2","status":"publish","type":"post","link":"https:\/\/anandalue.com\/?p=638","title":{"rendered":"wordpress\u6587\u7ae0\u9875\u4e2d\u5982\u4f55\u6dfb\u52a0\u731c\u4f60\u559c\u6b22"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>wordpress\u4e2d\u6709\u6807\u7b7e\u9875\uff08tags\uff09\u7684\u8bbe\u7f6e\uff0c\u4f46\u662f\u5374\u6ca1\u80fd\u5b9e\u73b0\u76f8\u5173tag\u6587\u7ae0\u7684\u63a8\u8350\u529f\u80fd<\/p>\n<p>\u901a\u8fc7\u63d2\u4ef6\u4e5f\u53ef\u5b9e\u73b0\uff0c\u4f46\u6211\u4eec\u8fd8\u662f\u672c\u7740\u80fd\u7701\u5219\u7701\u7684\u539f\u5219\uff0c\u5206\u4eab\u4ee3\u7801\u7ed9\u5927\u5bb6\u3002<\/p>\n<p><span style=\"color: #ff0000;\">\u00a0<\/span><\/p>\n<pre class=\"brush:php\">&lt;h3&gt;\u731c\u4f60\u559c\u6b22 &lt;\/h3&gt;\n\n&lt;?php\n$post_tags=wp_get_post_tags($post-&gt;ID); \/\/\u5982\u679c\u5b58\u5728tag\u6807\u7b7e\uff0c\u5217\u51fatag\u76f8\u5173\u6587\u7ae0\n$pos=1;\nif($post_tags) {\nforeach($post_tags as $tag) $tag_list[] .= $tag-&gt;term_id;\n$args = array(\n'tag__in' =&gt; $tag_list,\n'category__not_in' =&gt; array(NULL), \/\/ \u4e0d\u5305\u62ec\u7684\u5206\u7c7bID\n'post__not_in' =&gt; array($post-&gt;ID),\n'showposts' =&gt; 0, \/\/ \u663e\u793a\u76f8\u5173\u6587\u7ae0\u6570\u91cf\n'caller_get_posts' =&gt; 1,\n'orderby' =&gt; 'rand'\n);\nquery_posts($args);\nif(have_posts()):while (have_posts()&amp;&amp;$pos&lt;=5) : the_post(); update_post_caches($posts); ?&gt;\n&lt;li&gt;&lt;span&gt;&lt;a href=\"&lt;?php the_permalink(); ?&gt;\" rel=\"bookmark\" title=\"&lt;?php the_title_attribute(); ?&gt;\"&gt;&lt;?php if(get_the_title())the_title();else the_time('Y-m-d'); ?&gt;&lt;\/a&gt;&lt;\/span&gt; &lt;span&gt;&lt;?php the_time('Y-m-d') ?&gt; &lt;?php the_category('\/','') ?&gt;&lt;\/span&gt;&lt;\/li&gt;\n&lt;?php $pos++;endwhile;wp_reset_query();endif; ?&gt;\n&lt;?php } \/\/end of rand by tags ?&gt;\n&lt;?php if($pos&lt;=5): \/\/\u5982\u679ctag\u76f8\u5173\u6587\u7ae0\u5c11\u4e8e5\u7bc7\uff0c\u90a3\u4e48\u7ee7\u7eed\u4ee5\u5206\u7c7b\u4f5c\u4e3a\u76f8\u5173\u56e0\u7d20\u5217\u51fa\u76f8\u5173\u6587\u7ae0\n$cats = wp_get_post_categories($post-&gt;ID);\nif($cats){\n$cat = get_category( $cats[0] );\n$first_cat = $cat-&gt;cat_ID;\n$args = array(\n'category__in' =&gt; array($first_cat),\n'post__not_in' =&gt; array($post-&gt;ID),\n'showposts' =&gt; 0,\n'caller_get_posts' =&gt; 1,\n'orderby' =&gt; 'rand'\n);\nquery_posts($args);\nif(have_posts()): while (have_posts()&amp;&amp;$pos&lt;=5) : the_post(); update_post_caches($posts); ?&gt;\n&lt;li&gt;&lt;span&gt;&lt;a href=\"&lt;?php the_permalink(); ?&gt;\" rel=\"bookmark\" title=\"&lt;?php the_title_attribute();?&gt;\"&gt;&lt;?php if(get_the_title())the_title();else the_time('Y-m-d'); ?&gt;&lt;\/a&gt;&lt;\/span&gt; &lt;span&gt;&lt;?php the_time('Y-m-d');if($options['tags']):the_tags('', '\/', '');endif; ?&gt;&lt;\/span&gt;&lt;\/li&gt;\n&lt;?php $pos++;endwhile;wp_reset_query();endif; ?&gt;\n&lt;?php } endif; \/\/end of rand by category ?&gt;\n&lt;?php if($pos&lt;=5){ \/\/\u5982\u679c\u4e0a\u9762\u4e24\u79cd\u76f8\u5173\u90fd\u8fd8\u4e0d\u591f5\u7bc7\u6587\u7ae0\uff0c\u518d\u968f\u673a\u6311\u51e0\u7bc7\u51d1\u62105\u7bc7 ?&gt;\n&lt;?php query_posts('showposts=5&amp;orderby=rand');while(have_posts()&amp;&amp;$pos&lt;=5):the_post(); ?&gt;\n&lt;li&gt;&lt;span&gt;&lt;a href=\"&lt;?php the_permalink(); ?&gt;\" title=\"&lt;?php the_title(); ?&gt;\"&gt;&lt;?php if(get_the_title())the_title();else the_time('Y-m-d') ?&gt;&lt;\/a&gt;&lt;\/span&gt; &lt;span&gt;[ &lt;?php the_category('\/',''); ?&gt;]&lt;\/span&gt;&lt;\/li&gt;\n&lt;?php $pos++;endwhile;wp_reset_query();?&gt;\n&lt;?php } ?&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u63d2\u5165\u5230\u5916\u89c2\u300b\u7f16\u8f91\u300bsingle.php \u6587\u7ae0\u9875\u9762\u4e2d<\/p>\n<p>\u5177\u4f53\u4f4d\u7f6e\uff0c\u4f60\u5148\u7528\u5ba1\u67e5\u5143\u7d20\u8003\u5bdf\u4e00\u4e0b\u518d\u63d2\u5165\u3002<\/p>\n<pre class=\"brush:php\">&lt;?php if(!themify_check('setting-comments_posts')): ?&gt;<\/pre>\n<p>\u4e00\u822c\u90fd\u653e\u5728\u8fd9\u4e0a\u9762\uff08\u8bc4\u8bba\u6846\u4ee3\u7801\uff09\u4e4b\u524d\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; wordpress\u4e2d\u6709\u6807\u7b7e\u9875\uff08tags\uff09\u7684\u8bbe\u7f6e\uff0c\u4f46\u662f\u5374\u6ca1\u80fd\u5b9e\u73b0\u76f8\u5173tag\u6587\u7ae0\u7684\u63a8\u8350\u529f\u80fd \u901a\u8fc7\u63d2\u4ef6\u4e5f\u53ef\u5b9e\u73b0\uff0c\u4f46\u6211\u4eec\u8fd8\u662f\u672c\u7740\u80fd\u7701\u5219\u7701\u7684\u539f\u5219\uff0c\u5206\u4eab\u4ee3\u7801\u7ed9\u5927\u5bb6\u3002 \u00a0 &lt;h3&gt;\u731c\u4f60\u559c\u6b22 &lt;\/h3&gt; &lt;?php $post_tags=wp_get_post_tags($post-&gt;ID); \/\/\u5982\u679c\u5b58\u5728tag\u6807\u7b7e\uff0c\u5217\u51fatag\u76f8\u5173\u6587\u7ae0 $pos=1; if($post_tags) { foreach($post_tags as $tag) $tag_list[] .= $tag-&gt;term_id; $args = array( &#8216;tag__in&#8217; =&gt; $tag_list, &#8216;category__not_in&#8217; =&gt; array(NULL), \/\/ \u4e0d\u5305\u62ec\u7684\u5206\u7c7bID &#8216;post__not_in&#8217; =&gt; array($post-&gt;ID), &#8216;showposts&#8217; =&gt; 0, \/\/ \u663e\u793a\u76f8\u5173\u6587\u7ae0\u6570\u91cf &#8216;caller_get_posts&#8217; =&gt; 1, &#8216;orderby&#8217; =&gt; &#8216;rand&#8217; ); query_posts($args); if(have_posts()):while (have_posts()&amp;&amp;$pos&lt;=5) : the_post(); update_post_caches($posts); ?&gt; &lt;li&gt;&lt;span&gt;&lt;a href=&#8221;&lt;?php the_permalink(); ?&gt;&#8221;&hellip; <a class=\"more-link\" href=\"https:\/\/anandalue.com\/?p=638\">Continue reading <span class=\"screen-reader-text\">wordpress\u6587\u7ae0\u9875\u4e2d\u5982\u4f55\u6dfb\u52a0\u731c\u4f60\u559c\u6b22<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-638","post","type-post","status-publish","format-standard","hentry","category-course","entry"],"_links":{"self":[{"href":"https:\/\/anandalue.com\/index.php?rest_route=\/wp\/v2\/posts\/638"}],"collection":[{"href":"https:\/\/anandalue.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anandalue.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anandalue.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/anandalue.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=638"}],"version-history":[{"count":0,"href":"https:\/\/anandalue.com\/index.php?rest_route=\/wp\/v2\/posts\/638\/revisions"}],"wp:attachment":[{"href":"https:\/\/anandalue.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anandalue.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anandalue.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}