Posts dont display date
-
Hello!
I designed my first wordpress site for my wife’s blog about a year ago, and somehow I managed to hide the date on all her posts! I cant seem to figure out how to get it back – if it’s a css thing, or if I have to add some code to the functions.php.The site is http://atactilelife.com.au
Could anyone help?
Thanks!
Ryan
-
It doesn’t appear to be hidden by CSS. If you examine the content.php file, about halfway down do you see a section that starts like this:
<footer class="entry-meta"> <?php twentytwelve_entry_meta(); ?>I dont! But I inserted <?php the_date(‘Y-m-d’, ‘<h2>’, ‘</h2>’); ?> as per http://codex.wordpress.org/Function_Reference/the_date and it’s worked! I was trying to put it into a functions.php and index.php and everything but content! Thank you!!!!
Now I just need to style it to make it look better.
Any way I can change the text to ‘posted by author on the_date‘?
So I’ve managed to get the date to display on the front page through content.php but when I click on a link to an actual post, the date disappears.
Which .php file do I edit to put it into an individual post?
And the bigger question – when I inspect an element through a browser like firefox or chrome, is there a way I can tell which .php file I should be editing?
I’m surprised that the date doesn’t show up on the single post page.
This link details the Template Hierarchy. The template hierarchy determines which files get called depending upon the context and on the presence of other files. For the blog page, index.php gets called. It is also the default file that gets called when displaying a category, tag, or archive page, if there is no category.php, tag.php, or archive.php file present.
For single posts, single.php is called. If you look inside the single.php file of the TwentyTwelve theme, you should see a couple of lines that look like this (if your single.php file hasn’t been modified):
<?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', get_post_format() ); ?>That is, single.php retrieves a file called content.php to display the post content. That’s why I had you look at content.php, because that’s the subtemplate that’s being included by single.php. If you look at index.php, which displays the blog entries, you should see an identical section.
Now, it’s possible that the posts have a specific format assigned to them, like Image. If you go and edit a post, in the Format section on the right, if anything other than Standard is selected, then you’ll need to look at the other content-xxxx.php files, where xxxx is the specific post format. For example, if the post format is Image, then you need to edit content-image.php to make sure it displays the date.
Thanks for your help, CrouchingBruin. That all makes complete logical sense to me – that’s why it doesnt make sense to me why it’s not working!
The format of the post is indeed Standard. I might just go through and add my
<h2 class="entrydate">Posted on <?php the_date('F j Y'); ?></h2>to each of the different content-xxxx.php files just in case. It can’t hurt!For fun here is the entire code of content.php, just in case something weird pops out to you!
<?php /** * The default template for displaying content. Used for both single and index/archive/search. * * @package WordPress * @subpackage Twenty_Twelve * @since Twenty Twelve 1.0 */ ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <?php if ( is_sticky() && is_home() && ! is_paged() ) : ?> <div class="featured-post"> <?php _e( 'Featured post', 'twentytwelve' ); ?> </div> <?php endif; ?> <header class="entry-header"> <?php the_post_thumbnail(); ?> <?php if ( is_single() ) : ?> <h1 class="entry-title"><?php the_title(); ?></h1> <?php else : ?> <h1 class="entry-title"> <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'twentytwelve' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_title(); ?></a> </h1><h2 class="entrydate">Posted on <?php the_date('F j Y'); ?></h2> <?php endif; // is_single() ?> </header><!-- .entry-header --> <?php if ( is_search() ) : // Only display Excerpts for Search ?> <div class="entry-summary"> <?php the_excerpt(); ?> </div><!-- .entry-summary --> <?php else : ?> <div class="entry-content"> <?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentytwelve' ) ); ?> <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'twentytwelve' ), 'after' => '</div>' ) ); ?> </div><!-- .entry-content --> <?php endif; ?> <?php if ( comments_open() ) : ?> <div class="comments-link"> <?php comments_popup_link( '<span class="leave-reply">' . __( 'COMMENT', 'twentytwelve' ) . '</span>', __( '1 Reply', 'twentytwelve' ), __( '% Replies', 'twentytwelve' ) ); ?> </div><!-- .comments-link --> <?php endif; // comments_open() ?>Ah, OK, that was very helpful. The problem is that you added the code for entrydate in the else part of an if-then-else structure. Let me indent it properly so it’s easier to see:
<?php if ( is_single() ) : ?> <h1 class="entry-title"><?php the_title(); ?></h1> <?php else : ?> <h1 class="entry-title"> <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'twentytwelve' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_title(); ?></a> </h1><h2 class="entrydate">Posted on <?php the_date('F j Y'); ?></h2> <?php endif; // is_single() ?>The first line says “If this is a single post page” (as opposed to a multiple post page, like an index page).
The second line outputs the post title.
The third line starts the else section, which executes if it’s not a single post page, i.e., a blog page. This section ends at the last line, which reads endif. Notice that the entry title is also output in this section, but the title is output as a link so the user can click on the entry title to go to the single post. The line for the date is also in this section, which is why it only appears on the blog page.The solution is to simply move the line of code which outputs the date to just after the endif statement so it gets output regardless of whether it’s in a single post page or an index page. Leave the closing h1 tag inside the else section.
Yes!!! That’s it.
CrouchingBruin – you’re my Hero of the Day.That’s what I like about these problems, you end up learning so much!
The topic ‘Posts dont display date’ is closed to new replies.
