Forums

Archive of current category listed in sidebar (3 posts)

  1. chloraldo
    Member
    Posted 1 month ago #

    Hi all

    Is there a way to display an archive of the current category in the sidebar?

    Example:
    When you navigate to a post in a category there should appear a list of the posts in that but only that category.

    How can I do that?

    Thanks

  2. MichaelH
    moderator
    Posted 1 month ago #

    In a sidebar, if single post, for the first category of that post, display 5 posts in that category, excluding the single post.

    Related:
    http://wordpress.org/search/category+single+sidebar?forums=1
    http://wordpress.org/support/topic/257858?replies=4
    http://wordpress.org/support/topic/179138?replies=4
    http://wordpress.org/support/topic/252228

    <?php
    if ( is_single() ) {
      $cats = wp_get_post_categories($post->ID);
        if ($cats) {
        $first_cat = $cats[0];
        $args=array(
          'cat' => $first_cat, //cat__not_in wouldn't work
          'post__not_in' => array($post->ID),
          'showposts'=>5,
          'caller_get_posts'=>1
        );
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          echo 'Related Posts';
          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;
        } //if ($my_query)
      } //if ($cats)
      wp_reset_query();  // Restore global post data stomped by the_post().
    } //if (is_single())
    ?>
  3. Shane G
    Member
    Posted 1 month ago #

    Hi,

    Check with this plugin:

    http://wordpress.org/extend/plugins/category-based-archives/

    Thanks,

    Shane G.

Reply

You must log in to post.

About this Topic