• 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)
  • Thread Starter frankfolk

    (@frankfolk)

    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.

    <ul>
            	<?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 }; ?>
            </ul>

    use setup_postdata(); in the loop – http://codex.wordpress.org/Template_Tags/get_posts#Examples

    and be aware of the behaviour of the_date() – see SPECIAL NOTE in http://codex.wordpress.org/Function_Reference/the_date

    Thread Starter frankfolk

    (@frankfolk)

    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.