I'm trying to add the post content in the header but for some reason it doesn't show anything. However it does retrieve the post content.

I wrote this:

<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<?php the_title(); ?>
<?php the_content(); ?>

I tried and and none showed anything...

Is there any way I can archive this? I really need it for the site's navigation. Thanks


The simplest solution is to call the_post() to setup the post data before calling the template functions.

<?php if(have_posts()) : the_post(); ?>
  //your header code here
  <?php rewind_posts(); //to set the post pointer back to the beginning ?>
<?php else : ?>
  //alternative header code here
<?php endif; ?>
  • Thanks a lot it works if I put it inside the header in an if. It breaks the theme if I call it before anything. – Lisandro Dec 15 '10 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy