admin管理员组文章数量:1306126
I need to show the event date instead of the (default) post date for each post.
How can I do this?
I tried with Event Post plugin, but I can't get the event date and put it overwriting the published post date.
I tried with a custom field too (using Advanced Custom Field plugin), but I have the same problem: I can't replace the post date with the "date picker field".
For me it's important to use the default post format of wp and not a plugin that adds item "Events" in the wp backend menu.
How can I resolve this? IMO the wp developers should include the possibility to change the date status from published to event date.
Many thanks in advance.
I need to show the event date instead of the (default) post date for each post.
How can I do this?
I tried with Event Post plugin, but I can't get the event date and put it overwriting the published post date.
I tried with a custom field too (using Advanced Custom Field plugin), but I have the same problem: I can't replace the post date with the "date picker field".
For me it's important to use the default post format of wp and not a plugin that adds item "Events" in the wp backend menu.
How can I resolve this? IMO the wp developers should include the possibility to change the date status from published to event date.
Many thanks in advance.
Share Improve this question asked Nov 23, 2016 at 10:24 user3437268user3437268 351 gold badge2 silver badges5 bronze badges 1- If you want to use Advanced Custom Fields, this is how to display a date - put this in your single.php / index.php / archive.php template(s) in your theme where you want the date to display: advancedcustomfields/resources/date-picker/#template-usage That is how to change the display on the site. In the admin, you'll still have the post date as the day you published the post. – Michelle Commented Nov 23, 2016 at 17:22
2 Answers
Reset to default 1Ok, great. It is using the posts for concerts, parties...etc.
You need to create a plugin:
Simply, create a folder inside the /wp-content/plugins and name is /my-events-plugin
Create a new PHP file, name it my_events_plugin.php, and use the following template:
https://www.smashingmagazine/2011/09/how-to-create-a-wordpress-plugin/
There is this tutorial that will get you to adding the custom field and save it:
https://www.smashingmagazine/2011/10/create-custom-post-meta-boxes-wordpress/
Hope this gets you going :)
i had to do it, i was looking for something very simple : just add a date event to some post to show it in archive of my news (it can be a start date and a end date also).
You need to add custom field to posts by adding a metabox to post screen, easyly with ACF plugin, or by yourself coding it in your theme's functions.php or in a self made plugin...
For example _my_evt_date, you will find it in postmeta table as meta_key with a meta_value like 2020-12-24 string.
The idea is to make a query in this table to store in an array each post having such meta key, you can create a json multiple array with post_id, date, html to display ...
In the archive page showing your news posts thumbnails, look at html code of each article in the loop, you'll probably have a css class including the post id, maybe like "post-entry-3217", "post-entry-3218"....
It was my case but using a premium template i decide to use javascript with jQuery to:
- call my database query with jQuery.get to load in a js array my php array with dates information
- parse article blocks matching css class post-entry-xxxx,
- extract the post id xxxx
- create a loop and parse the js array till matching the related post_id
- insert with jQuery.append some html with date information above the related thumbnail
js :
jQuery(document).ready(function()
{
// only in the archive page
if( jQuery('.slide-entry').length )
{
jQuery.get({
url:'mywebsite-uri/wp-content/themes/my-child-theme/my-script.php',
success: function(data)
{
// Load in an array results
ckc_yaevt = jQuery.parseJSON(data);
jQuery('.slide-entry').each(function()
{
// Extract xxxx from each slide-entry-xxxx
var post_id = jQuery(this).attr('class').match(/\d+/);
// Parse array with posts having dates
for (var i=0; i<ckc_yaevt.length; i++)
{
if ( ckc_yaevt[i][0] === post_id[0] && ckc_yaevt[i][1] !== '' )
{
// Add html in the loop
jQuery('.slide-image',this).append(ckc_yaevt[i][1]);
break;
}
}
})
}
})
}
})
Result :
本文标签: How replace post date with event date
版权声明:本文标题:How replace post date with event date 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741813639a2398947.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论