• webhostph

    (@webhostph)


    Anyone knows how to do this thing? I want to show the post title on the sidebar so when they click it, it will go directly to the post and not on the subcategory.
    Can I bypass the subcategory and instead the title of the post will appear?

    Category Title1
    Post Title1
    Post Title2
    Category Title 2
    Post Title1
    Post Title2

    Is this achievable?

    Because currently when using the list_category() it is like this:

    Category 1
    Subcategory 1
    Subcategory 2
    Category 2
    Subcategory 1
    Subcategory 2

Viewing 1 replies (of 1 total)
  • MichaelH

    (@michaelh)

    <?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().
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Post title instead of subcategory on sidebar’ is closed to new replies.