• Following on from here:

    http://wordpress.org/support/topic/200913?replies=3

    It turns out this isn’t resolved, as when i rename $post to $thepost it fixes the comments but breaks the displaying of the_title(), the_permalink() and the_title_attribute();

    Here is my code:

    <div class="MoreCat">
    		<?php
    		$categories = get_the_category();
    		foreach ($categories as $category) :
    		?>
    		<h3>Similar recent articles</h3>
    			<?php
    			$posts = get_posts('numberposts=5&category='. $category->term_id);
    				foreach($posts as $post) :
    				$values = get_post_meta($post->ID, "Image", true);
    			if (isset($values[0])) { ?>
    			<div class="MoreCatImg">
    			<img src="<?php bloginfo('template_url'); ?>/scripts/timthumb.php?src=<?php echo $values; ?>&amp;w=102&amp;h=102&amp;zc=1&amp;q=85" alt="<?php the_title(); ?>" />
    			<div class="MoreCatText">
    			<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    			</div>
    			</div>
    		<?php } ?>
    		<?php endforeach; ?>
    		<?php endforeach; ?>
    		</div>
Viewing 1 replies (of 1 total)
  • I added

    <?php foreach($posts as $post) :?>
    <?php endforeach; ?>

    and everything works the it should.

    this is the code I use

    <?php foreach($myposts as $post) :?>
     <ul><li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li></ul>
    <?php endforeach; ?>
    <?php foreach($posts as $post) :?>
    <?php endforeach; ?>

Viewing 1 replies (of 1 total)

The topic ‘Using $post in foreach loop breaks comments on single.php’ is closed to new replies.