• Resolved designrf

    (@designrf)


    Hi everybody,

    I created 3 categories (Artists / Labels / Publishers), each contain few posts. Instead of display the name and the post number of a category, i would like to know how to display all posts title in the category in the sidebar.
    For example :
    Artists
    – title post 1
    – title post 2
    – title post 3
    Labels
    – title post 1
    – title post 2
    – title post 3
    Publishers
    – title post 1
    – title post 2
    – title post 3

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php
    //get all terms (e.g. categories or post tags), 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'
     );
    $terms = get_terms($taxonomy,$term_args);
    if ($terms) {
      foreach( $terms as $term ) {
        $args=array(
          "$param_type" => array($term->term_id),
          '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().
    ?>
    Thread Starter designrf

    (@designrf)

    Cheers! It’s what i wanted. Very good. I thought WordPress had an option to do that easily.

    Regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display posts title from categories in sidebar’ is closed to new replies.