如前所述,这是一个可以使用metabox向客户提供的解决方案。您可以将其复制/粘贴到functions.php
:
add_action( \'add_meta_boxes\', \'bullet1545_add_custom_box\' );
add_action( \'save_post\', \'bullet1545_save_custom_meta_box\' );
function bullet1545_add_custom_box( $post ) {
add_meta_box(
\'Bullet Meta Box\', // ID, should be a string
\'Side List\', // Meta Box Title
\'bullet1545_custom_meta_box_content\', // Your call back function, this is where your form field will go
\'post\', // The post type you want this to show up on, can be post, page, or custom post type
\'normal\', // The placement of your meta box, can be normal or side
\'high\' // The priority in which this will be displayed
);
}
function bullet1545_save_custom_meta_box(){
global $post;
// Get our form field
if( $_POST ) :
$bullet1545_custom_meta = esc_attr( $_POST[\'bullet1545-custom-meta-box\'] );
// Update post meta
update_post_meta($post->ID, \'_bullet1545_custom_meta\', $bullet1545_custom_meta);
endif;
}
function bullet1545_custom_meta_box_content( $post ) {
// Get post meta value using the key from our save function in the second paramater.
$bullet1545_custom_meta = get_post_meta($post->ID, \'_bullet1545_custom_meta\', true);
echo \'<label>Custom Meta Box:</label>
\';
echo \'<textarea name="bullet1545-custom-meta-box">\'.$bullet1545_custom_meta.\'</textarea>\';
}
这将为您的后期编辑页面提供一个文本区域。
现在在您的页面中显示前端。php,您可以使用该代码:
<?php
$myBullets = get_post_meta(get_the_ID(), "_bullet1545_custom_meta", true); // retrieve the content of your metabox
echo \'<ul>\';
$textareaData = \'<li>\'.str_replace(array("\\r","\\n\\n","\\n"),array(\'\',"\\n","</li>\\n<li>"),trim($myBullets,"\\n\\r")).\'</li>\'; // this line converts all the lines that are inside your textarea in li lines, removing empty lines
echo \'</ul>\';
?>
我希望它尽可能清楚。使用此解决方案,您不必维护插件,网站所有者也不必使用li标签。