jeudi 9 juin 2016

Wordpress - Recent Posts code in Header Menu breaking Post Data

I have custom code that shows the latest 2 blog posts in my site's header menu.

<?php
$recentPosts = new WP_Query();
$recentPosts->query('showposts=2');
while ($recentPosts->have_posts()) :
$recentPosts->the_post();
?>

<?php the_permalink(); ?>
<?php the_post_thumbnail_url('thumbnail'); ?>
<?php the_title(); ?>
<?php the_excerpt(); ?>

<?php endwhile; ?>

It works perfectly, except for when I view an actual blog post in Wordpress. For example, when viewing a blog post where the title is supposed to show the_title();...instead of it showing the actual post's title, it instead shows the title from the last "recent post" in the header menu.

So somehow I need to make this Recent Posts code in the header unique to itself, to where it doesn't affect data on an actual blog post page. Any ideas?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire