• Resolved noregt

    (@noregt)


    Hello everyone from WordPress. I’ve got a site running here, based on the magazeen template (simplified version).

    What I’ve done, just to make navigation less blog alike, is that I’ve placed the categories in the header.
    In the sidebar I would like to show the posts related to the category that you are looking at. Now I did install the category posts plugin, but that only enables you to show a specific category that you have to set in the Dashboard.

    I’ll probably have to make a custom query to make it dynamic? And can I use the loop from the index file (because the sidebar is included in the index page)?

Viewing 2 replies - 1 through 2 (of 2 total)
  • I would like to show the posts related to the category that you are looking at

    Category Templates do display the posts in a category. Anyway, here’s something you might use in your sidebar.php:

    <?php
    if ( is_category() ) {
      $cat = get_query_var('cat');
      $args = array(
        'orderby' => 'date',
        'order' => 'DESC',
        'post_type' => 'post',
        'numberposts' => 8,
        'category__in' => array($cat)
      );
      $posts=get_posts($args);
      if ($posts) {
        foreach($posts as $post) {
          setup_postdata($post);
          ?>
          <p><?php the_time('m.d.y') ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php }
      }
    }
    ?>

    Thread Starter noregt

    (@noregt)

    Well that works brilliantly I must say. I’m an absolute beginner with wordpress, so had no clue about the category template. But the script works directly, no plugins needed!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Show posts depending on a dynamic category’ is closed to new replies.