wordpress调用所有分类及分类下的文章


wordpress调用所有分类及分类下的文章代码:

<?php
    $cats = get_categories();
    foreach ( $cats as $cat ) {
    query_posts( 'showposts=10&cat=' . $cat->cat_ID );
?>
    <h3><?php echo $cat->cat_name; ?></h3>
    <ul class="sitemap-list">
        <?php while ( have_posts() ) { the_post(); ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <?php } wp_reset_query(); ?>
    </ul>
<?php } ?>

get_categories调用所有目录,调用当前文章分类目录get_the_category。

调用当前所在分类目录文章,并倒叙显示代码:

<?php
    $cats = get_the_category();
    foreach ( $cats as $cat ) {
    query_posts( 'showposts=10&order=asc&cat=' . $cat->cat_ID );
?>
    <h3><?php echo $cat->cat_name; ?></h3>
    <ul class="sitemap-list">
        <?php while ( have_posts() ) { the_post(); ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <?php } wp_reset_query(); ?>
    </ul>
<?php } ?>

标签:

文章发布时间:2020-05-22