• I’ve modified my loop to show a thumbnail and title only. So far, so good. The list is a list of all the posts from one category. Now I need to organize it. The list of posts now needs to be sorted by sub category. I’d like to list the sub category as a title for the section. This is one bit of code that I just cannot seem to find in the forum or on the internet.

    Example:
    Sub Category 1
    -Lesson 1
    -Lesson 2
    Sub Category 2
    -Lesson 1
    -Lesson 2

    Here is my loop code so far:

    <ul class="listofposts">
    
    		<?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>
    	<li>
    	<div class="list-title"<?php post_class() ?> id="post-<?php the_ID(); ?>">
    			<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to 			<?php the_title_attribute(); ?>">
    			<img src="<?php echo catch_that_image() ?>" width="50" height="50" 						align="middle"/>
    			<?php the_title(); ?></a>
    	</li>
    
    	<?php endwhile; ?>
    </ul>
    
    	<?php next_posts_link('&laquo; Older Entries') ?>
    	<?php previous_posts_link('Newer Entries &raquo;') ?>
    	</div><!-- closes .list-title -->
    
    <?php else : ?>

Viewing 1 replies (of 1 total)
  • Something like:

    <?php
    //get all terms child of category 3, then display all posts in each term
    $taxonomy = 'category';//  e.g. post_tag, category
    $param_type = 'category__in'; //  e.g. tag__in, category__in
    $term_args=array(
      'orderby' => 'name',
      'order' => 'ASC',
      'child_of' => 3
    );
    $terms = get_terms($taxonomy,$term_args);
    if ($terms) {
      foreach( $terms as $term ) {
        $args=array(
          "$param_type" => array($term->term_id),
          'order' => 'ASC',
          'orderby' => 'title',
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => -1,
          'caller_get_posts'=> 1
          );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          echo 'List of Posts in '.$taxonomy .' '.$term->name;
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
           <?php
          endwhile;
        }
      }
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

Viewing 1 replies (of 1 total)
  • The topic ‘List by category and sub category & show category name’ is closed to new replies.