我正在尝试找到一种方法来选择日期并将其显示在Wordpress页面中。简单地说,这就是它可能的工作方式:
我不想要自动或当前日期,我可以用这个plugin做。任何人都可以通过插件或PHP代码片段来帮助实现这一点吗?
发布于 2018-09-20 07:34:06
在Settings->Reading
中显示自定义日期字段
function wpse_52414489_custom_date() {
// Add the section to reading settings so we can add our
// fields to it
add_settings_section(
'eg_custom_settings',
'My custom settings',
'',
'reading'
);
// Add the field with the names and function to use for our new
// settings, put it in our new section
add_settings_field(
'eg_custom_date',
'My custom date',
'eg_custom_date_callback',
'reading',
'eg_custom_settings'
);
// Register our setting so that $_POST handling is done for us and
// our callback function just has to echo the <input>
register_setting( 'reading', 'eg_custom_date' );
}
function eg_custom_date_callback() {
echo '<input name="eg_custom_date" id="eg_custom_date" type="date" value="' . get_option( 'eg_custom_date' ) . '" class="code" /> Explanation text';
}
add_action( 'admin_init', 'wpse_52414489_custom_date' );
添加您的快捷方式(编辑:自定义日期格式):
add_filter( 'init', function() {
add_shortcode( 'my-custom-date', function() {
return date( 'd/m/Y', strtotime( get_option( 'eg_custom_date' ) ) );
});
});
用法:
[my-custom-date]
输出:
2018-09-18
https://stackoverflow.com/questions/52414489
复制相似问题