• How can i display all post that belong a category as a navigation?
    I’m currently using this.

    <?php while (have_posts()) : the_post(); ?>
        <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
        <li>~</li>
    <?php endwhile; ?>

    This is in my header.php

    This works, but once i’m in a particular entry, it will only display the current entry it’s in, but not any sibling entries belonging to the same category.

Viewing 1 replies (of 1 total)
  • This works, but once i’m in a particular entry, it will only display the current entry it’s in, but not any sibling entries belonging to the same category.

    That’s the way the Template Hierarchy works for single post views. If you want to display, in a single.php, all the posts that have the same category for that single post then put something like this in your single.php template:

    <?php
    if ( is_single() ) {
      $categories = get_the_category();
      if ($categories) {
        foreach ($categories as $category) {
          // echo "<pre>"; print_r($category); echo "</pre>";
          $cat = $category->cat_ID;
          $args=array(
            'cat' => $cat,
            'post__not_in' => array($post->ID),
            'showposts'=>5,
            'caller_get_posts'=>1
          );
          $my_query = new WP_Query($args);
          if( $my_query->have_posts() ) {
            echo '<h2>More Posts from '. $category->category_description . '</h2>';
            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)
        } //foreach ($categories
      } //if ($categories)
      wp_reset_query();  // Restore global post data stomped by the_post().
    } //if (is_single())
    ?>

    Related:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

Viewing 1 replies (of 1 total)
  • The topic ‘Get all post links under one category’ is closed to new replies.