How do I show current post content in the header?
-
16-10-2019 - |
سؤال
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; ?>
لا تنتمي إلى wordpress.stackexchange