Site logo

Archived topic

Customizing blog archive date display

3 replies · Started by Matthew on January 18, 2022

Viewing posts 1–4 of 4

Hi,

I am trying to customize the display of the blog archive on a child theme, specifically the way the author and date are displayed. The settings within the Customizer are not enough to achieve the required look, so in the content.php template underneath <?php the_excerpt(); ?> I added code from the WordPress repository to display the date:

<?php the_date( 'M d, Y', '<time>', '</time>' ); ?>

You can see it in action here: https://manyrequests.com/blog

Funny thing is, this only displays the date on a few select posts within the loop. There is no rhyme or reason to the ones with(out) dates, it is the strangest thing. Nothing is wrong with the database either (ex: published/updated dates) but perhaps I am going about this entire thing the wrong way.

Is there any easier way to customize the GeneratePress date/author beyond the basic show/hide options within the Customizer? Or might anyone have a suggestion as to what I'm doing wrong to get intermittent dates on blog posts? I am absolutely baffled and would greatly appreciate any suggestions, thank you! :)

Hi there,

the_date() function does some funny things when used in the loop - for starters it will only return a unique date - so if there are multiple posts published on the same date, only the first one will display the date... the others will be empty.

Better to use either:

get_the_date or the_time functions

Regarding GP - yeah theres plenty of filters that allow you to modify the meta but we are kinda pushing users towards using the Block Element for displaying Dynamic Data eg.

https://docs.generatepress.com/article/block-element-post-meta-template/

To note: if its just the date formating that needs to change then you can change that in WordPress settings for all dates

Hey David,

Whoa, I had not noticed the Post Meta element before, that is excellent! Thank you so much for the link, just what I needed :)

Glad to be of help

This archived topic is closed to new replies.