我如何列出 WordPress 中的所有类别和所有帖子,如下例所示:
CATEGORY1
POSTS
CATEGORY2
POSTS
CATEGORY3
POSTS
Run Code Online (Sandbox Code Playgroud)
尝试下面的代码:
\n\n <?php // get all the categories from the database\n$cats = get_categories();\n// loop through the categries\nforeach ($cats as $cat) {\n// setup the cateogory ID\n$cat_id= $cat->term_id;\n// Make a header for the cateogry\necho \xe2\x80\x9c<h2>\xe2\x80\x9d.$cat->name.\xe2\x80\x9d</h2>\xe2\x80\x9d;\n// create a custom wordpress query\nquery_posts(\xe2\x80\x9ccat=$cat_id&post_per_page=100\xe2\x80\xb3);\n\nif (have_posts()) : while (have_posts()) : the_post(); ?>\n\n<?php // create our link now that the post is setup ?>\n\n<a href=\xe2\x80\x9d<?php the_permalink();?>\xe2\x80\x9d><?php the_title(); ?></a>\n\n<?php echo \xe2\x80\x98<hr/>\xe2\x80\x99; ?>\n\n<?php endwhile; endif;\n// done our wordpress loop. Will start again for each category ?>\n\n<?php } // done the foreach statement ?>\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
6185 次 |
| 最近记录: |