Wordpress Custom Field/ Meta Box for a specific Post/Page
I know you can easily add custom meta boxes per post type, but I'm looking to add a custom meta box / custom field for a specific page without getting away from the wordpress 'pages' menu.
So for example, when I go to Pages-> Edit 'Home' a box called welcome text shows up.
If I edit the page 'About', that box wont show up.
A开发者_开发百科ny ideas?
If you want to decide on the edit page whether to add a meta box or not, hook into the add_meta_boxes
or add_meta_boxes_page
(for the page
post type) actions. They are called right before the boxes are drawn, so you can choose to add one via add_meta_box
.
You should be able to use the Custom_Fields property on the pages you want to add data to. For example. On the "Home" page add a custom field "welcome_text" then use something like
$customField = get_post_custom_values("welcome_text");
if (isset($customField[0])) {
echo $customField[0];
}
inside the home template. I'm sure there are other ways but this may be the simpliest.
Perhaps WPAlchemy MetaBox might help...
精彩评论