0

i have problem. I use this code before comment form.

<?php

global $post;

$args = array( 'posts_per_page' => 5, 'offset'=> 1, 'category' => 1 );

$myposts = get_posts( $args );

foreach ( $myposts as $post ) : setup_postdata( $post ); ?>

        <?php the_permalink(); ?><?php the_title(); ?>

<?php endforeach; ?>

I have in single.php:

1 -- post content

2 -- recent post

3 -- form comment

But when i comment something my comment is not on post but was added to last recent post. How can i do this?

I tried to use this:

<?php
$args = array(
    'posts_per_page'   => 1,
    'category__not_in' => array( 23, 24 )
);

$recent_posts = get_posts( $args );

foreach ( $recent_posts as $recent ) {
    echo '<a href="' . get_permalink( $recent ) . '">Latest Post</a>';
}
?>

1 Answer 1

0

You should add wp_reset_postdata after outputting your recent posts.

1
  • Ya that is what i need. Thx.
    – user33913
    Commented Aug 6, 2013 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.