31
Mar/10
0

WordPress on the frontpage – displays category content, but not title

So here’s an interesting one. Often I have sites with a page where there is a subcategory with a few of the latest entries fully featured on the front page. The following code, when I tried it, did not display the title for the subcategory entries. Instead of the subcategory post title I got the main page title.

<?php
 $newsposts = get_posts('numberposts=2&category=4');
 foreach($newsposts as $newspost_single) :
 setup_postdata($newspost_single);
?>
 <div>
 <h3><?php the_title(); ?></h3>
 <?php the_content(); ?>
 <hr>

 </div>
<?php endforeach; ?>

The fix? To change theĀ $newspost_single variable to $post. Not sure why this is the fix, and I should see if it counts as a bug, but it worked for me.

Filed under: Wordpress
Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.