列出类别/child 类别/大child 类别/post 标题

List categories / child categories / grandchild categories / post titles

我找到了这段代码:

<?php 
$args = array(
  'orderby' => 'id',
  'hide_empty'=> 0,
  'child_of' => 2,
'depth' => 5,
);
$categories = get_categories($args);
 foreach ($categories as $cat) {
    echo '<div>';
    echo '<h1>'.$cat->name.'<img src="'.$cat->term_icon.'" alt=""  class="alignleft"/>'.'<br />'.'<span class="solutions">'.$cat->description.'</span>'.'</h1>';
    //echo '<br />';     
 $args3= array("orderby"=>'name', "category" => $cat->cat_ID, 'depth' => 5); // Get Post from each Sub-Category
    $posts_in_category = get_posts($args3);
    foreach($posts_in_category as $current_post) {
        echo '<span>';
        ?>
        <li><h1><a href="<?=$current_post->guid;?>"><?=$current_post->post_title;?></a></li></h1>
        <?php
        echo '</span>';
    }
    echo '</div>';
}
?>

这会列出所有类别和某个类别中的 post。但我想要它来自所有类别。但是当我填写 'child_of' => 2 时,它会列出所有内容,但格式不正确。 grandchilds 与 children.

具有相同的等级地位

我想要的例如:

所以:所有的猫都应该能够处理posts,如果grandchildren中只有posts,只列出那些……谢谢! -edit- 实际上它应该与 wp_list_categories 相同,只有我应该能够编辑 parents、children、grandchildren 和 post 标题分别地。 (例如,我必须能够删除 child-categories 的 href,但不能删除 grandchild-categories..

试试这个:

   <!-- Category Archive Start -->
    <ul class="catArchive">
    <?php
    $catQuery = $wpdb->get_results("SELECT * FROM $wpdb->terms AS wterms INNER JOIN $wpdb->term_taxonomy AS wtaxonomy ON ( wterms.term_id = wtaxonomy.term_id ) WHERE wtaxonomy.taxonomy = 'category' AND wtaxonomy.parent = 0 AND wtaxonomy.count > 0");

    $catCounter = 0;

    foreach ($catQuery as $category) {

        $catCounter++;

        $catStyle = '';
        if (is_int($catCounter / 2)) $catStyle = ' class="catAlt"';

        $catLink = get_category_link($category->term_id);

        echo '<li'.$catStyle.'><h3><a href="'.$catLink.'" title="'.$category->name.'">'.$category->name.'</a></h3>';
            echo '<ul style="margin-left:15px;">';

            query_posts('category__in='.$category->term_id.'&showposts=5');?>

            <?php while (have_posts()) : the_post(); ?>
                <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
            <?php endwhile; ?>

                <li><a href="<?php echo $catLink; ?>" title="<?php echo $category->name; ?>">More <strong><?php echo $category->name; ?></strong></a></li>
         <li> <?php
         $sub_cat_id = $category->term_id;
         $get_sub_args = array('child_of' =>$sub_cat_id);
                 $categories_arr =  get_categories($get_sub_args);  
                 //print_r ($categories_arr);
        foreach  ($categories_arr as $sacategory) {
                //Display the sub category information using $category values like $category->cat_name
                echo '<h2>'.$sacategory->name.'</h2>';
                echo '<ul style="margin-left:15px;">';

                foreach (get_posts('cat='.$sacategory->term_id) as $post) {
                    setup_postdata( $post );
                    echo '<li><a href="'.get_permalink($post->ID).'">'.get_the_title().'</a></li>';   
                }  
                echo '</ul>';
            }

         ?></li>



            </ul>
        </li>
        <?php } ?>
    </ul>
    <!-- Category Archive End -->
        </div>