admin管理员组文章数量:1022997
Is there a way (plugin, or something else) to set it where there is a drop down on the "New Post" page that allows you to choose a post type and the fields change allowing you to filter what content you are putting into a post without confusing a user by having 20 different custom fields on the "New Post" page.
Also, is there a plugin or other that can make custom fields with different value types (textarea, list, file upload, etc)?
Is there a way (plugin, or something else) to set it where there is a drop down on the "New Post" page that allows you to choose a post type and the fields change allowing you to filter what content you are putting into a post without confusing a user by having 20 different custom fields on the "New Post" page.
Also, is there a plugin or other that can make custom fields with different value types (textarea, list, file upload, etc)?
Share Improve this question asked Feb 4, 2011 at 5:54 Jo AlbrightJo Albright 1431 silver badge7 bronze badges 2- Welcome to WordPress Answers on StackExchange. Glad to have you here. Since you are new and likely unfamiliar with how things are designed to work here I'd like to let you know that you should only ask one question per question so please answer another question about the custom fields with different value types. – MikeSchinkel Commented Feb 4, 2011 at 12:12
- I apologize, is there an easy way to do that without creating two questions? And is there a way to mark two answers correct on one question? – Jo Albright Commented Feb 4, 2011 at 14:07
2 Answers
Reset to default 1This was asked over and over:
- Add custom field automatically to custom page types
- Redesigning Custom Post Type “Add New” page
and if you are not into coding the you can use plugins like
- Simple fields
- More Fields
- Verve Meta Boxes
hope this helps
I understand your concern; if you get a lot of post types WordPress' admin menu quickly grows unwieldy. What I've done for you is to implement something like what you asked for. It creates a post edit page metabox for the new post page with a drop down list of custom post types like this:
And here's what it looks like with a bunch of custom post types in the drop down mode:
What it does is use jQuery and Javascript to modify window.location.href
in the browser's DOM upon selection using one of the following URL patterns, using the post types in my list of screenshots as an example:
http://example/wp-admin/post-new.php // This is for post_type=post
http://example/wp-admin/post-new.php?post_type=page
http://example/wp-admin/post-new.php?post_type=actor
http://example/wp-admin/post-new.php?post_type=movie
http://example/wp-admin/post-new.php?post_type=car
http://example/wp-admin/post-new.php?post_type=event
http://example/wp-admin/post-new.php?post_type=performer
One thing I worry about is the usability of this, however, so I wrote it to disable the drop down after the user modifies the value of any input field. That way the user can't accidently loose everything they were working on.
The code follows and you can place this in your theme's functions.php
file or in a .php
file for a plugin that you might be writing:
add_action('add_meta_boxes', 'add_meta_boxes_post_type_switcher',10,2);
function add_meta_boxes_post_type_switcher($post_type,$post) {
global $pagenow;
if ($pagenow=='post-new.php') {
require_once(ABSPATH . 'wp-admin/includes/template.php');
add_meta_box('post_type_switcher','Change Post Type',
'post_type_switcher',$post_type,'side','high');
}
}
function post_type_switcher($post,$metabox) {
$post_types = get_post_types();
$new_post_url = admin_url('post-new.php');
$js =<<<JS
<script type="text/javascript">
jQuery(document).ready(function ($) {
$("#post-type-switcher-selector").change(function() {
var post_type = $(this).find(":selected").val();
var new_post_type_url = "{$new_post_url}?post_type=" + post_type;
if (post_type=="post" && "{$new_post_url}"!=window.location.href) {
window.location.href = "{$new_post_url}";
} else if (new_post_type_url!=window.location.href) {
window.location.href = new_post_type_url;
}
});
$(".wp-admin #wpbody-content :input").change(function() {
$("#post-type-switcher-selector").attr("disabled","disabled");
});
});
</script>
JS;
echo $js;
echo '<select id="post-type-switcher-selector">';
foreach ( $post_types as $post_type ) {
$post_type_object = get_post_type_object($post_type);
if ($post_type_object->publicly_queryable && $post_type!='attachment') {
echo "\n\t<option ";
if ( $post_type == $post->post_type ) // Make default first in list
echo "selected='selected' ";
echo "value='{$post_type}'>";
echo $post_type_object->labels->singular_name;
echo "</option>";
}
}
echo '</select>';
}
So there's the code and it should work for you. If you have any questions about specifics in the code, just ask. However I would recommend you instead consider a consolidated menu like this one instead since I think it creates a more consistent mental model for the user, but the choice is yours!
Is there a way (plugin, or something else) to set it where there is a drop down on the "New Post" page that allows you to choose a post type and the fields change allowing you to filter what content you are putting into a post without confusing a user by having 20 different custom fields on the "New Post" page.
Also, is there a plugin or other that can make custom fields with different value types (textarea, list, file upload, etc)?
Is there a way (plugin, or something else) to set it where there is a drop down on the "New Post" page that allows you to choose a post type and the fields change allowing you to filter what content you are putting into a post without confusing a user by having 20 different custom fields on the "New Post" page.
Also, is there a plugin or other that can make custom fields with different value types (textarea, list, file upload, etc)?
Share Improve this question asked Feb 4, 2011 at 5:54 Jo AlbrightJo Albright 1431 silver badge7 bronze badges 2- Welcome to WordPress Answers on StackExchange. Glad to have you here. Since you are new and likely unfamiliar with how things are designed to work here I'd like to let you know that you should only ask one question per question so please answer another question about the custom fields with different value types. – MikeSchinkel Commented Feb 4, 2011 at 12:12
- I apologize, is there an easy way to do that without creating two questions? And is there a way to mark two answers correct on one question? – Jo Albright Commented Feb 4, 2011 at 14:07
2 Answers
Reset to default 1This was asked over and over:
- Add custom field automatically to custom page types
- Redesigning Custom Post Type “Add New” page
and if you are not into coding the you can use plugins like
- Simple fields
- More Fields
- Verve Meta Boxes
hope this helps
I understand your concern; if you get a lot of post types WordPress' admin menu quickly grows unwieldy. What I've done for you is to implement something like what you asked for. It creates a post edit page metabox for the new post page with a drop down list of custom post types like this:
And here's what it looks like with a bunch of custom post types in the drop down mode:
What it does is use jQuery and Javascript to modify window.location.href
in the browser's DOM upon selection using one of the following URL patterns, using the post types in my list of screenshots as an example:
http://example/wp-admin/post-new.php // This is for post_type=post
http://example/wp-admin/post-new.php?post_type=page
http://example/wp-admin/post-new.php?post_type=actor
http://example/wp-admin/post-new.php?post_type=movie
http://example/wp-admin/post-new.php?post_type=car
http://example/wp-admin/post-new.php?post_type=event
http://example/wp-admin/post-new.php?post_type=performer
One thing I worry about is the usability of this, however, so I wrote it to disable the drop down after the user modifies the value of any input field. That way the user can't accidently loose everything they were working on.
The code follows and you can place this in your theme's functions.php
file or in a .php
file for a plugin that you might be writing:
add_action('add_meta_boxes', 'add_meta_boxes_post_type_switcher',10,2);
function add_meta_boxes_post_type_switcher($post_type,$post) {
global $pagenow;
if ($pagenow=='post-new.php') {
require_once(ABSPATH . 'wp-admin/includes/template.php');
add_meta_box('post_type_switcher','Change Post Type',
'post_type_switcher',$post_type,'side','high');
}
}
function post_type_switcher($post,$metabox) {
$post_types = get_post_types();
$new_post_url = admin_url('post-new.php');
$js =<<<JS
<script type="text/javascript">
jQuery(document).ready(function ($) {
$("#post-type-switcher-selector").change(function() {
var post_type = $(this).find(":selected").val();
var new_post_type_url = "{$new_post_url}?post_type=" + post_type;
if (post_type=="post" && "{$new_post_url}"!=window.location.href) {
window.location.href = "{$new_post_url}";
} else if (new_post_type_url!=window.location.href) {
window.location.href = new_post_type_url;
}
});
$(".wp-admin #wpbody-content :input").change(function() {
$("#post-type-switcher-selector").attr("disabled","disabled");
});
});
</script>
JS;
echo $js;
echo '<select id="post-type-switcher-selector">';
foreach ( $post_types as $post_type ) {
$post_type_object = get_post_type_object($post_type);
if ($post_type_object->publicly_queryable && $post_type!='attachment') {
echo "\n\t<option ";
if ( $post_type == $post->post_type ) // Make default first in list
echo "selected='selected' ";
echo "value='{$post_type}'>";
echo $post_type_object->labels->singular_name;
echo "</option>";
}
}
echo '</select>';
}
So there's the code and it should work for you. If you have any questions about specifics in the code, just ask. However I would recommend you instead consider a consolidated menu like this one instead since I think it creates a more consistent mental model for the user, but the choice is yours!
本文标签: custom fieldHow to change what the post creation page looks like
版权声明:本文标题:custom field - How to change what the post creation page looks like? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745507409a2153668.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论