如何在 Wordpress 页面中显示所需日期?
How can I display a desired date into a Wordpress page?
我正在尝试寻找一种方法来选择日期并将其显示到 Wordpress 页面中。
简而言之,这就是它的运作方式:
- 通过 PHP insert
将一个或多个页面输入简码或 PHP 代码
- operator/webmaster 从比方说日历或下拉菜单中选择一个日期
- 此日期(格式化)显示在具有 shortcode/PHP 代码
的页面中
我不想要我可以用这个 plugin 做的自动或当前日期。
任何人都可以通过插件或 PHP 片段帮助实现这一目标吗?
在 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
我正在尝试寻找一种方法来选择日期并将其显示到 Wordpress 页面中。 简而言之,这就是它的运作方式:
- 通过 PHP insert 将一个或多个页面输入简码或 PHP 代码
- operator/webmaster 从比方说日历或下拉菜单中选择一个日期
- 此日期(格式化)显示在具有 shortcode/PHP 代码 的页面中
我不想要我可以用这个 plugin 做的自动或当前日期。 任何人都可以通过插件或 PHP 片段帮助实现这一目标吗?
在 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