Post date under post title
-
Hi,
I want to thank you for you great plugin. It is the best out there so far.
I was wondering of the way to add the date of the post under the post title. I want my related posts to have the date beneath them.Thank you
-
Hi ananzeh25
You can override the template files used by this plugin.
http://keesiemeijer.wordpress.com/related-posts-by-taxonomy/templates/Use the WordPress function get_the_date() in a template of your own.
http://codex.ww.wp.xz.cn/Template_Tags/get_the_dateHere is an example for the links template (related-posts-links.php) with the date after the post title: http://pastebin.com/0hRR1GZn
Follow the instructions for the first method in the link above to have it use this template.
Hi,
Thank you for you reply. What I did that I added
<span class=”related-post-date”><?php echo get_the_date(); ?></span>
to all of the four templates so I can see quick result but nothing happened.I think I need to place the code somewhere in the function file. My related posts are taxonomy and thumbnail/gallery related functionality.
Thank you,
IbraDoes it work with the links format?
For adding the date to the post thumbnail captions you’ll need to use this filter.
http://keesiemeijer.wordpress.com/related-posts-by-taxonomy/filters/#related_posts_by_taxonomy_captionHere’s an example for in your theme’s functions.php:
add_filter( 'related_posts_by_taxonomy_caption', 'km_rpbt_add_date_to_caption', 10, 3); function km_rpbt_add_date_to_caption($caption, $related, $args ) { $caption .= '<span class="related-post-date">'; $caption .= get_the_date( get_option( 'date_format' ), $related->ID); $caption .= '</span>'; return $caption; }btw:
consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost. Or create a plugin with the code above.Thank you keesiemeijer
Working as it suppose to. The date didn’t work with the link template.
Here what I tried to do is to replace the title with the date and it is working. I did that because i work in photos gallery theme.
add_filter( 'related_posts_by_taxonomy_caption', 'link_related_caption', 10, 2 ); function link_related_caption( $caption, $post ){ $caption = get_the_date( get_option( 'date_format' ), $related->ID); return $caption; }I was wondering though how to locate the date before the title.
The above code doesn’t bring the right date here the right one:
add_filter( 'related_posts_by_taxonomy_caption', 'link_related_caption', 10, 2 ); function link_related_caption( $caption, $related, $args ){ $caption .= '<span class="related-post-date">'; $caption = get_the_date( get_option( 'date_format' ), $related->ID); $caption .= '</span>'; return $caption; }Still can’t figure how to locate the post title under the post date.
Try it with this:
add_filter( 'related_posts_by_taxonomy_caption', 'link_related_caption', 10, 3 ); function link_related_caption( $caption, $related, $args ) { $date = '<span class="related-post-date">'; $date .= get_the_date( get_option( 'date_format' ), $related->ID ); $date .= '</span>'; return $date . $caption; }It works.
Thank you!You’re welcome. I’m glad you’ve got it resolved π
Hey, I’m a little lost with this. Can you specify where I’m supposed to post this code? I put it in themes functions.php file and it didn’t work. I want to display the date underneath the image above the title. Thank you!
Yes, in your theme’s functions.php.
Does it still show the title without the date?
Ok I added the code you provided below to functions.php
add_filter( 'related_posts_by_taxonomy_caption', 'link_related_caption', 10, 2 ); function link_related_caption( $caption, $related, $args ) { $date = '<span class="related-post-date">'; $date .= get_the_date( get_option( 'date_format' ), $related->ID ); $date .= '</span>'; return $date . $caption; }The title is showing, so now I’m assuming I add a code to show the date on the template. I tried <span class=”related-post-date”><?php echo get_the_date(); ?></span> but that only shows the date for one post, if that’s the code where do I place it?
If not, What do I add to the related-posts-thumbnails.php file? I want the date to be above the title. Thank you! π
For adding the date to the thumbnail gallery captions you don’t have to add code to the templates.
Try changing this in your theme’s functions.php file:
add_filter( 'related_posts_by_taxonomy_caption', 'link_related_caption', 10, 2 );to this:
add_filter( 'related_posts_by_taxonomy_caption', 'link_related_caption', 10, 3 );It worked! Thank you!!
The topic ‘Post date under post title’ is closed to new replies.