{"id":645809,"date":"2012-08-06T15:41:36","date_gmt":"2012-08-06T15:41:36","guid":{"rendered":"http:\/\/www.xptt.com\/?p=645809"},"modified":"2014-11-03T21:16:09","modified_gmt":"2014-11-03T13:16:09","slug":"wordpress-blog-home-specify-the-classification-of-the-article","status":"publish","type":"post","link":"https:\/\/xptt.com\/645809.html","title":{"rendered":"WordPress\u535a\u5ba2\u9996\u9875\u663e\u793a\u6307\u5b9a\u5206\u7c7b\u7684\u6587\u7ae0"},"content":{"rendered":"<p>\u4eca\u5929\u770b\u5230\u6709WordPress\u535a\u4e3b\u5728\u95ee\u201cWordPress\u535a\u5ba2\u9996\u9875\u5982\u4f55\u6392\u9664\u6307\u5b9a\u5206\u7c7b\u7684\u6587\u7ae0\uff1f\u201d\u3002\u7528\u6237\u4e3a\u4ec0\u4e48\u60f3\u8fd9\u6837\u505a\u7684\u539f\u56e0\u6709\u5f88\u591a\uff0c\u4e5f\u8bb8\u4f60\u4e0d\u5e0c\u671b\u5728\u9996\u9875\u4e0a\u663e\u793a\u4e0a\u663e\u793a\u81ea\u5df1\u751f\u6d3b\u7c7b\u7684\u6587\u7ae0\uff0c\u800c\u53ea\u663e\u793a\u4e00\u4e9b\u65b0\u95fb\u7c7b\u7684\u6587\u7ae0\u3002<\/p>\n<p>\u8981\u505a\u5230\u8fd9\u4e00\u70b9\uff0c\u4f60\u5c31\u9700\u8981\u5728 <a href=\"http:\/\/codex.wordpress.org\/The_Loop\" target=\"_blank\">The loop<\/a> \u4e2d\u66f4\u6539\u8c03\u7528\u6587\u7ae0\u7684\u51fd\u6570\u3002WordPress\u9ed8\u8ba4\u4e3b\u9898 Twenty Ten \u548c Twenty Eleven \u4f7f\u7528 <a href=\"http:\/\/codex.wordpress.org\/Function_Reference\/the_post\" target=\"_blank\">the_post()<\/a> \u51fd\u6570\u6765\u8c03\u7528\u6240\u6709\u7684\u535a\u5ba2\u6587\u7ae0\u3002<\/p>\n<blockquote><p>&lt;?php while ( have_posts() ) : the_post(); ?&gt;<\/p><\/blockquote>\n<p><a href=\"http:\/\/codex.wordpress.org\/Function_Reference\/the_post\" target=\"_blank\">the_post()<\/a> \u51fd\u6570\u4f7f\u7528 <a href=\"http:\/\/codex.wordpress.org\/Class_Reference\/WP_Query\" target=\"_blank\">WP_Query<\/a>\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 WP_Query \u51fd\u6570\u672c\u8eab\u6765\u81ea\u5b9a\u4e49\u54ea\u4e9b\u6587\u7ae0\u88ab\u8c03\u7528\uff0c\u6216\u8005\u54ea\u4e9b\u5b58\u6863\u3001\u5206\u7c7b\u3001\u65f6\u95f4\u7684\u6587\u7ae0\u53ef\u4ee5\u663e\u793a\u5728\u4e3b\u9875\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u4f7f\u7528 <a href=\"http:\/\/codex.wordpress.org\/Template_Tags\/query_posts\" target=\"_blank\">query_posts<\/a> \u51fd\u6570\u6765\u63a7\u5236 The Loop \u5faa\u73af\u3002\u8fd9\u79cd\u65b9\u6cd5\u65e0\u7591\u662f\u6700\u597d\u7684\uff0c\u56e0\u4e3a\u5b83\u5e76\u6ca1\u6709\u6539\u53d8\u4f60\u7684\u5faa\u73af\u3002\u4e0d\u8fc7\uff0c\u4e24\u79cd\u65b9\u6cd5\u6211\u90fd\u4f1a\u8bb2\u89e3\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u4e00\u4e2a\u9002\u5408\u4f60\u7684\u3002<br \/>\n<strong>\u4f7f\u7528\u51fd\u6570WP_Query<\/strong><br \/>\n\u5982\u679c\u4f60\u60f3\u6539\u53d8\u4f60\u7684\u4e3b\u9875\u663e\u793a\u6548\u679c\uff0c\u4f60\u9700\u8981\u7f16\u8f91\u4f60\u7684\u4e3b\u9898index.php\u6587\u4ef6\u3002\u5927\u90e8\u5206\u4e3b\u9898\u4f7f\u7528archive.php\u6587\u4ef6\u6765\u4f5c\u4e3a\u5206\u7c7b (category)\u3001\u65f6\u95f4(date)\u3001\u6807\u7b7e(tag)\u7684\u7684\u663e\u793a\u9875\u9762\uff0c \u6240\u4ee5\u4f60\u60f3\u66f4\u6539\u67d0\u4e2a\u5b58\u6863\u9875\u9762\u53ea\u8981\u4fee\u6539archive.php\u6587\u4ef6\u5c31\u53ef\u4ee5\u4e86\u3002\u8fd8\u6709\u4e00\u4e9b\u4e3b\u9898\u6709\u4e13\u95e8\u7684category.php\u3001date.php\u3001 tag.php\u6a21\u677f\uff0c\u4fee\u6539\u76f8\u5bf9\u5e94\u7684\u5c31\u597d\u3002<\/p>\n<p>\u5927\u591a\u6570\u4e3b\u9898\u6587\u4ef6\u7684\u5faa\u73af\u4f1a\u4ee5\u201cStart the Loop\u201d\u5f00\u59cb\u3002\u4f8b\u5982\u5728Twenty Eleven\u4e3b\u9898\u4e2d\uff0c\u770b\u8d77\u6765\u50cf\u8fd9\u6837\uff1a<\/p>\n<blockquote><p>&lt;?php \/* Start the Loop *\/ ?&gt;<br \/>\n&lt;?php while ( have_posts() ) : the_post(); ?&gt;<br \/>\n\u4f60\u9700\u8981\u66ff\u6362\u4e3a\u4ee5\u4e0b\u51fd\u6570\uff1a<br \/>\n\/\/ The Query<br \/>\n$query = new WP_Query( $args );<\/p>\n<p>\/\/ The Loop<br \/>\nwhile ( $query-&gt;have_posts() ) : $query-&gt;the_post();<\/p><\/blockquote>\n<p>\u8981\u63a7\u5236\u54ea\u4e9b\u6587\u7ae0\u5728\u5faa\u73af\u4e2d\u663e\u793a\uff0c\u4f60\u9700\u8981\u5b9a\u4e49\u5728<a href=\"http:\/\/codex.wordpress.org\/Class_Reference\/WP_Query\" target=\"_blank\">WP_Query<\/a>\u4e2d\u7684\u53c2\u6570\uff0c\u5373\u4fee\u6539 $query = new WP_Query( $args );.<\/p>\n<p>\u76ee\u524d\u67095\u79cd\u53c2\u6570\uff0c\u6bd4\u8f83\u5e38\u7528\u7684\u662f\u53c2\u6570\u662f <strong>cat<\/strong> \u548c <strong>category_name\u00a0 <\/strong>\u3002<\/p>\n<p>\u82e5\u4f60\u8981\u663e\u793a\u4f60\u7684 tech \u5206\u7c7b\uff0c\u800c\u5b83\u7684\u5206\u7c7bID\u662f1\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u4f7f\u7528\u53c2\u6570cat\uff1a<\/p>\n<blockquote><p>$query = new WP_Query( 'cat=1' );<\/p><\/blockquote>\n<p>\u6216\u8005\u4f60\u53ef\u4ee5\u4f7f\u7528\u53c2\u6570 category_name \u6765\u8fbe\u5230\u540c\u6837\u7684\u6548\u679c\uff1a<\/p>\n<blockquote><p>$query = new WP_Query( 'category_name=tech' );<\/p><\/blockquote>\n<p>\u82e5\u60f3\u591a\u6dfb\u52a0\u51e0\u4e2a\u5206\u7c7b\uff0c\u5219\u9700\u8981\u7528\u9017\u53f7\u5206\u9694\u3002<\/p>\n<blockquote><p>$query = new WP_Query( 'cat=1,7,121' );<\/p>\n<p>\u6216<\/p>\n<p>$query = new WP_Query( 'category_name=news,reviews,tutorials' );<\/p><\/blockquote>\n<p>\u5728\u5206\u7c7bID\u524d\u52a0\u4e0a\u51cf\u53f7\u6765\u6392\u9664\u67d0\u4e00\u7c7b\u7684\u6240\u6709\u6587\u7ae0\u3002\u6ce8\u610f\uff0c\u4e0d\u53ef\u4ee5\u4f7f\u7528category_name \u53c2\u6570\u6765\u6392\u9664\u7c7b\u522b\u3002<\/p>\n<blockquote><p>$query = new WP_Query( 'cat=-1' );<\/p><\/blockquote>\n<p>\u5728\u4e0a\u9762\u8bf4\u8fc7\uff0c\u67095\u79cd\u53c2\u6570\uff0c\u6211\u5df2\u7ecf\u8bb2\u89e3\u4e86\u5176\u4e2d\u4e24\u4e2a\uff1a<strong>cat<\/strong> \u548c <strong>category_name<\/strong>\uff0c\u90fd\u662f\u4ece\u4f60\u7684\u6587\u7ae0\u5217\u8868\u4e2d\u5305\u542b\u6216\u6392\u9664\u67d0\u4e9b\u7c7b\u522b\u3002<\/p>\n<p>\u5176\u4ed6\u4e09\u4e2a\u53c2\u6570\u662f category_and\u3001category_in\u548ccategory_not_in\u3002<\/p>\n<blockquote><p>category_and\u663e\u793a\u591a\u4e2a\u5206\u7c7b\u7684\u6587\u7ae0\uff1a<br \/>\n$query = new WP_Query( array( 'category__and' =&gt; array( 1, 7 ) ) );<br \/>\ncategory_in\u662f\u4e00\u4e2aor\u51fd\u6570\uff1a<br \/>\n$query = new WP_Query( array( 'category__in' =&gt; array( 7, 127 ) ) );<br \/>\n\u6392\u9664\u591a\u4e2a\u7c7b\u522b\uff1a<br \/>\n$query = new WP_Query( array( 'category__not_in' =&gt; array( 2, 6 ) ) );<\/p><\/blockquote>\n<p>WP Query\u662f\u4e00\u4e2a\u975e\u5e38\u7075\u6d3b\u7684\u529f\u80fd\u51fd\u6570\u3002\u5206\u7c7b\u53ea\u662f\u5176\u4e2d\u7684\u4e00\u4e2a\u53c2\u6570\u800c\u5df2\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<ul>\n<li><strong>Author Parameters<\/strong> \u2013 \u663e\u793a\u67d0\u4e2a\u4f5c\u8005\u6216\u591a\u4e2a\u4f5c\u8005\u7684\u6587\u7ae0\u5217\u8868\uff0c\u4e5f\u53ef\u4ee5\u6392\u9664\u4e4b\u3002<\/li>\n<li><strong>Tag Parameters<\/strong> \u2013 \u663e\u793a\u6216\u6392\u9664\u67d0\u4e9bTag\u7684\u6587\u7ae0\u5217\u8868\u3002<\/li>\n<li><strong>Taxonomy Parameters<\/strong> \u2013 \u663e\u793a\u4e00\u4e2a\u6216\u591a\u4e2a\u81ea\u5b9a\u4e49\u5206\u7c7b\u7684\u6587\u7ae0\u5217\u8868\u3002.<\/li>\n<li><strong>Post &amp; Page Parameters<\/strong> \u2013 \u4f7f\u7528IDs \u6216 page slugs\u663e\u793a\u67d0\u4e9b\u7279\u5b9a\u7684\u6587\u7ae0\u3002<\/li>\n<li><strong>Type &amp; Status Parameters<\/strong> \u2013 \u663e\u793a\u67d0\u4e9b\u6587\u7ae0\u7c7b\u578b\u7684\u6587\u7ae0\u6216\u5e26\u6709\u9644\u4ef6\u7684\u6587\u7ae0\u3002<\/li>\n<li><strong>Pagination Parameters<\/strong> \u2013 \u786e\u5b9a\u6bcf\u9875\u663e\u793a\u7684\u6587\u7ae0\u6570\u91cf\u3002<\/li>\n<li><strong>Offset Parameter<\/strong> \u2013 \u6587\u7ae0\u4ece\u67d0\u54ea\u5f00\u59cb\u663e\u793a\u3002<\/li>\n<li><strong>Order &amp; Orderby Parameters<\/strong> \u2013 \u66f4\u6539\u6587\u7ae0\u5217\u8868\u7684\u6392\u5217\u987a\u5e8f\u3002<\/li>\n<li><strong>Sticky Post Parameters<\/strong> \u2013 \u663e\u793a\u5305\u62ec\u6216\u6392\u9664\u7f6e\u9876\u6587\u7ae0\u7684\u6587\u7ae0\u5217\u8868\u3002<\/li>\n<li><strong>Time Parameters<\/strong> \u2013 \u663e\u793a\u67d0\u4e9b\u65f6\u95f4\u6bb5\u7684\u6587\u7ae0\u3002<\/li>\n<li><strong>Custom Field Parameters<\/strong> \u2013 \u663e\u793a\u76f8\u5173\u81ea\u5b9a\u4e49\u5b57\u6bb5\u7684\u6587\u7ae0\u3002<\/li>\n<li><strong>Permission Parameters<\/strong> \u2013 \u663e\u793a\u53d1\u5e03\u7684\u6216\u79c1\u5bc6\u7684\u6587\u7ae0\u3002<\/li>\n<\/ul>\n<p><a href=\"http:\/\/codex.wordpress.org\/Class_Reference\/WP_Query\" target=\"_blank\">WP_Query<\/a> \u9875\u9762\u4e3a\u6bcf\u4e2a\u53c2\u6570\u90fd\u63d0\u4f9b\u4e86\u4f8b\u5b50\uff0c\u8fd9\u91cc\u5c31\u4e0d\u4e00\u4e00\u8bb2\u89e3\u5177\u4f53\u7528\u6cd5\u4e86\u3002<br \/>\n<strong>\u4f7f\u7528\u51fd\u6570query_posts<\/strong><br \/>\n<a href=\"http:\/\/codex.wordpress.org\/Template_Tags\/query_posts\" target=\"_blank\">query_posts<\/a>\u53ef\u4ee5\u975e\u5e38\u7b80\u5355\u7684\u5b9a\u5236\u4f60\u5728\u9875\u9762\u4e0a\u663e\u793a\u7684\u6587\u7ae0\uff0c\u800c\u4e14\u4f60\u4e0d\u5fc5\u66f4\u6539\u73b0\u6709\u7684\u5faa\u73af\u4ee3\u7801\u3002<\/p>\n<blockquote><p>query_posts( $args );<\/p><\/blockquote>\n<p>\u8981\u4f7f\u7528\u5b83\u7684\u529f\u80fd\uff0c\u4f60\u5c31\u5fc5\u987b\u5728\u4f60\u7684loop\u5faa\u73af\u5f00\u59cb\u4e4b\u524d\u8c03\u7528\u5b83\u3002\u4f8b\u5982\uff1a<\/p>\n<blockquote><p>\/\/ The Query<br \/>\nquery_posts( $args );<\/p>\n<p>\/\/ The Loop<br \/>\nwhile ( have_posts() ) : the_post();<\/p><\/blockquote>\n<p>\u5982\u679c\u4f60\u8ba1\u5212\u8c03\u7528\u9875\u9762\u4e2d\u7684\u7b2c\u4e8c\u4e2a\u5faa\u73af\uff0c\u8bf7\u786e\u4fdd\u4f60\u4f7f\u7528\u4e86<a href=\"http:\/\/codex.wordpress.org\/Function_Reference\/wp_reset_query\" target=\"_blank\">wp_reset_query()<\/a>\u6765\u91cd\u7f6e\u4f60\u7684\u5faa\u73af\u3002\u4f8b\u5982\uff1a<\/p>\n<blockquote><p>\/\/ The Query<br \/>\n&lt;?php query_posts( $args ); ?&gt;<\/p>\n<p>&lt;?php \/* Start the Loop *\/ ?&gt;<br \/>\n&lt;?php while ( have_posts() ) : the_post(); ?&gt;<\/p>\n<p>&lt;?php get_template_part( 'content', get_post_format() ); ?&gt;<\/p>\n<p>&lt;?php endwhile; ?&gt;<br \/>\n&lt;?php wp_reset_query(); ?&gt;<\/p>\n<p>\u8981\u663e\u793a\u67d0\u4e9b\u5206\u7c7b\u7684\u6587\u7ae0\uff0c\u4f60\u9700\u8981\u7528\u5230 <strong>cat<\/strong> \u53c2\u6570\uff1a<br \/>\n&lt;?php query_posts( 'cat=1,5,6' ); ?&gt;<br \/>\n\u540c\u6837\uff0c\u8981\u6392\u9664\u67d0\u4e9b\u5206\u7c7b\uff0c\u4f60\u9700\u8981\u5728\u524d\u9762\u6dfb\u52a0\u51cf\u53f7\uff1a<br \/>\n&lt;?php query_posts( 'cat=-3,-5' ); ?&gt;<br \/>\n\u8fd8\u53ef\u4ee5\u7528\u6765\u663e\u793a\u7279\u5b9a\u7684\u6587\u7ae0\uff1a<br \/>\nquery_posts( 'p=2' );<br \/>\n\u8981\u5b9a\u4e49\u6bcf\u9875\u663e\u793a\u6587\u7ae0\u7684\u6570\u91cf\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 <strong>posts_per_page <\/strong>\u53c2\u6570\uff1a<br \/>\nquery_posts( 'posts_per_page=5' );<br \/>\n\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u7684\u4fe1\u606f\uff0c\u8bf7\u8bbf\u95ee<a href=\"http:\/\/codex.wordpress.org\/Template_Tags\/query_posts\" target=\"_blank\">query_posts<\/a>\u9875\u9762\u3002<\/p><\/blockquote>\n<p><strong>\u4f7f\u7528\u63d2\u4ef6\u6765\u6392\u9664\u67d0\u4e9b\u5206\u7c7b\u7684\u6587\u7ae0<\/strong><br \/>\n\u5bf9\u4e8e\u90a3\u4e9b\u5bf9\u4ee3\u7801\u4e0d\u592a\u611f\u5192\u7684\u670b\u53cb\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528WordPress\u63d2\u4ef6\u3002\u8fd9\u91cc\u5efa\u8bae\u4f7f\u7528<a href=\"http:\/\/wordpress.org\/extend\/plugins\/simply-exclude\/\" target=\"_blank\">Simply Exclude<\/a>\u548c<a href=\"http:\/\/wordpress.org\/extend\/plugins\/ultimate-category-excluder\/\" target=\"_blank\">Ultimate Category Excluder<\/a>\u3002<\/p>\n<p><strong><a href=\"http:\/\/wordpress.org\/extend\/plugins\/simply-exclude\/\" target=\"_blank\">Simply Exclude<\/a><\/strong><\/p>\n<p><a href=\"http:\/\/wordpress.org\/extend\/plugins\/simply-exclude\/\" target=\"_blank\">Simply Exclude<\/a>\u53ef\u4ee5\u8ba9\u4f60\u5728\u9996\u9875\u3001\u5f52\u6863\u9875\u3001\u641c\u7d22\u9875\u3001RSS\u4e2d\u6392\u9664\u6216\u5305\u542b\u67d0\u4e9b\u5206\u7c7b\u3001\u4f5c\u8005\u3001\u6807\u7b7e\u7684\u6587\u7ae0\uff0c\u4f7f\u7528\u8d77\u6765\u4e5f\u975e\u5e38\u7b80\u5355\u3002<\/p>\n<p><strong><a href=\"http:\/\/wordpress.org\/extend\/plugins\/ultimate-category-excluder\/\" target=\"_blank\">Ultimate Category Excluder<\/a><\/strong><\/p>\n<p><a href=\"http:\/\/wordpress.org\/extend\/plugins\/ultimate-category-excluder\/\" target=\"_blank\">Ultimate Category Excluder<\/a>\uff0c\u80fd\u8ba9\u4f60\u5bb9\u6613\u7684\u6392\u9664\u67d0\u4e9b\u5206\u7c7b\u5728\u4e3b\u9875\u3001\u5b58\u6863\u9875\u548cRSS\u4e2d\u3002\u4e0d\u540c\u4e8e<a href=\"http:\/\/wordpress.org\/extend\/plugins\/simply-exclude\/\" target=\"_blank\">Simply Exclude<\/a>\u7684\u662f\u4ed6\u53ea\u80fd\u6392\u9664\u67d0\u4e9b\u5206\u7c7b\uff0c\u4e0d\u80fd\u6392\u9664\u4f5c\u8005\u3001\u6807\u7b7e\u7b49\u3002<br \/>\n<strong>\u603b\u7ed3<\/strong><br \/>\n\u867d\u7136<a href=\"http:\/\/wordpress.org\/extend\/plugins\/simply-exclude\/\" target=\"_blank\">Simply Exclude<\/a>\u548c<a href=\"http:\/\/wordpress.org\/extend\/plugins\/ultimate-category-excluder\/\" target=\"_blank\">Ultimate Category Excluder<\/a>\u63d2\u4ef6\u90fd\u5f88\u4e0d\u9519\uff0c\u4f46\u5982\u679c\u4f60\u6709\u4e00\u5b9a\u7684\u7f16\u7a0b\u57fa\u7840\uff0c\u90a3\u4e48\u4f60\u8fd8\u662f\u624b\u52a8\u4fee\u6539\u5427\u3002<\/p>\n<p>\u539f\u6587\u5730\u5740\uff1a<span class=\"removed_link\" title=\"http:\/\/laygle.com\/2012\/01\/wordpress-exclude-categories\/\">http:\/\/laygle.com\/2012\/01\/wordpress-exclude-categories\/<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u770b\u5230\u6709WordPress\u535a\u4e3b\u5728\u95ee\u201cWordPress\u535a\u5ba2\u9996\u9875\u5982\u4f55\u6392\u9664\u6307\u5b9a\u5206\u7c7b\u7684\u6587\u7ae0\uff1f\u201d\u3002\u7528\u6237\u4e3a\u4ec0\u4e48\u60f3\u8fd9\u6837\u505a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"views":15771,"_links":{"self":[{"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/posts\/645809"}],"collection":[{"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/comments?post=645809"}],"version-history":[{"count":0,"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/posts\/645809\/revisions"}],"wp:attachment":[{"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/media?parent=645809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/categories?post=645809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xptt.com\/wp-json\/wp\/v2\/tags?post=645809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}