Support » Themes and Templates » In single.php list other articles in this category

  • Hello, i’m close to solving this problem but there is just something missing…

    Can someone please help. I am editing single.php and want a side bar that lists all other articles as links that are in the same category as this post. I would also like it to show the date that post was created.

    This is what i have:

    <?php foreach((get_the_category($post->ID)) as $category) { ?>
                	<a class ="postLink" href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br/>
                    <?php the_date(); ?> <br/>
                <?php }; ?>

    Basically, this just behaves strangely. If there is only one post in the category it posts the name twice and only one date. So guessing my loop isn’t working correctly.

    Anyone have and ideas?

Viewing 3 replies - 1 through 3 (of 3 total)
  • This is what i have now. And it works. But still struggling to incorporate the date. It only does it for the first entry in the loop.

            	<?php foreach((get_the_category($post->ID)) as $category) { ?>
            		<?php $catVal = $category->cat_ID; }
              	 $IDOutsideLoop = $post->ID;
              	 global $post;
            $myposts = get_posts('category='.$catVal.'&numberposts=999&order=ASC');
               foreach ($myposts as $post) { ?>
                 <li<?php if($IDOutsideLoop == $post->ID) { echo " class=\"current\""; } ?>>
                 <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                 <p> <?php the_date(); ?> </p>
            <?php }; ?>

    use setup_postdata(); in the loop –

    and be aware of the behaviour of the_date() – see SPECIAL NOTE in

    Brilliant. As soon as i used get_the_date() instead of the_date() it worked fine.

    my bad for being too inpatient to read the text hha.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘In single.php list other articles in this category’ is closed to new replies.