Date of post
-
I’m working with a theme that don’t show the date the post was made. What cod snippet do I need and in what PHP page should I put it, Page or Index.
Thank you in advance!
-
please, use $post->post_date
OK but how does the whole snippet look and in what page shall I out it?
You’ll need to edit page template. Inside loop use $post->post_date.
If it is not helpful, please, give the code of page.php and place you want to put date.
Fantastic, I really appreciate your help here. I want it just before the title of the post.
<body> <!-- WRAPPER --> <div id="wrapper"> <!-- BG WRAPPER --> <div id="bgwrapper"> <!-- HEADER + MENU --> <?php get_header(); ?> <!-- CONTAINER --> <div id="container"> <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2><?php the_title(); ?></h2> <div class="entry"> <?php the_content(); ?> <?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?> <?php edit_post_link('Edit', '<p>', '</p>'); ?> </div> </div> <?php endwhile; ?> <?php else : ?> <div class="post"> <h2><?php _e('Not Found'); ?></h2> </div> <?php endif; ?> </div> </div> <!-- FOOTER --> <?php get_footer(); ?> </div> </body>No – you shouldn’t use $post->post_date in this situation. You should use the_date() and/or the time().
Yes, esmi is correct, we can simply use the_date() or the_time() between
<?php while(have_posts()) : the_post(); ?>
…
<?php endwhile; ?>Try changing:
<h2><?php the_title(); ?></h2>to:
<div class="date><?php the_date();?></div> <h2><?php the_title(); ?></h2>Hmm that don’t lead to nothing? Ain’t got no class for date but I guess that don’t matter it should turn up anyway?
π
<div class="date><?php the_date();?></div>
is correct. place it where you want but keep it inside loop<?php while(have_posts()) : the_post(); ?>
…
<?php endwhile; ?>NEW CODE:
<body> <!-- WRAPPER --> <div id="wrapper"> <!-- BG WRAPPER --> <div id="bgwrapper"> <!-- HEADER + MENU --> <?php get_header(); ?> <!-- CONTAINER --> <div id="container"> <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <div class="date><?php the_date();?></div> <h2><?php the_title(); ?></h2> <div class="entry"> <?php the_content(); ?> <?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?> <?php edit_post_link('Edit', '<p>', '</p>'); ?> </div> </div> <?php endwhile; ?> <?php else : ?> <div class="post"> <h2><?php _e('Not Found'); ?></h2> </div> <?php endif; ?> </div> </div> <!-- FOOTER --> <?php get_footer(); ?> </div> </body>
The topic ‘Date of post’ is closed to new replies.