Forum Replies Created
-
AuthorPosts
-
November 18, 2012 at 5:53 pm in reply to: Suggestion: Be able to add metaboxes field to a specific page #428
James McMemberHere is the (tested) modification required to add page template specific metaboxes to your piklist plugin/theme. Very similar modification as the ID. This should help solve the whole ‘chicken or the egg’ issue with using an ID.
The following code can be copied and pasted over the current function in class-piklist-cpt.php
public static function register_meta_boxes_callback($arguments)
{
global $post, $pagenow;extract($arguments);
$current_user = wp_get_current_user();
$data = get_file_data($path . '/parts/' . $folder . '/' . $part, array(
'name' => 'Title'
,'context' => 'Context'
,'description' => 'Description'
,'capability' => 'Capability'
,'role' => 'Role'
,'priority' => 'Priority'
,'order' => 'Order'
,'type' => 'Post Type'
,'lock' => 'Lock'
,'collapse' => 'Collapse'
,'status' => 'Status'
,'new' => 'New'
,'id' => 'ID'
,'template' => 'Template'
));$types = empty($data['type']) ? get_post_types() : explode(',', $data['type']);
foreach ($types as $type)
{
$statuses = isset($data['status']) ? explode(',', $data['status']) : false;
$ids = isset($data['id']) ? explode(',', $data['id']) : false;if (post_type_exists($type)
&& (!$data['capability'] || ($data['capability'] && current_user_can(strtolower($data['capability']))))
&& (!$data['role'] || in_array(strtolower($data['role']), $current_user->roles))
&& (!$data['status'] || ($data['status'] && in_array($post->post_status, $statuses)))
&& (!$data['new'] || ($data['new'] && $pagenow != 'post-new.php'))
&& (!$data['id'] || ($data['id'] && in_array($post->ID, $ids)))
&& (!$data['template'] || ($data['template'] && $data['template'] == pathinfo(get_page_template_slug($post->ID), PATHINFO_FILENAME)))
)
{
$id = 'piklist_meta_' . piklist::slug($part);add_meta_box(
$id
,__($data['name'], 'piklist')
,array('piklist_cpt', 'meta_box')
,$type
,!empty($data['context']) ? $data['context'] : 'normal'
,!empty($data['priority']) ? $data['priority'] : 'low'
,array(
'part' => $part
,'add_on' => $add_on
,'order' => $data['order'] ? $data['order'] : null
,'config' => $data
)
);if (isset($data['lock']) && strtolower($data['lock']) == 'true')
{
add_filter("postbox_classes_{$type}_{$id}", array('piklist_cpt', 'lock_meta_boxes'));
}
if (isset($data['collapse']) && strtolower($data['collapse']) == 'true')
{
add_filter("postbox_classes_{$type}_{$id}", array('piklist_cpt', 'collapse_meta_boxes'));
}
add_filter("postbox_classes_{$type}_{$id}", array('piklist_cpt', 'default_classes'));
}
}
}
How to Use
Build your piklist meta-boxes field file with the following example header declaration:
/*
Title: Template Specific Page Metabox
Post Type: page
Template: full-width
*/
This example uses the Twenty Twelve theme page template called full-width.php in the page-templates theme directory. Basically you use the ‘slug’ or filename of the page template.
Once this is in place, change your page template, update the page and the meta-boxes you have specified for the template should be available for you to use.
For the interested…
The code uses a recently added function to WP for this to work. Sadly, the WP codex was not of much help…
November 17, 2012 at 1:44 pm in reply to: Suggestion: Be able to add metaboxes field to a specific page #425
James McMember@kattagami: if I have some time this weekend I’ll look into implementing this for you.
James McMemberSweet, looking forward to it.
James McMemberThanks for this. I hope Sandy didn’t wash Steve and Kevin away!
James McMember@Sarah: I’ve noticed that custom post statuses don’t appear in the quick edit status menu as well.
October 16, 2012 at 12:01 pm in reply to: Suggestion: Be able to add metaboxes field to a specific page #296
James McMemberNow that seems look a good idea and compromise. Also, its a feature that lends itself to interesting options for theme designers.
October 16, 2012 at 9:33 am in reply to: Suggestion: Be able to add metaboxes field to a specific page #293
James McMember@kattagami: The only way I can think about achieving this is to build a settings page where you could select page and meta-box pairs. When saving the settings, you would have to update the meta-box file with script. A little cumbersome.
Although, if Piklist had the facilities/functions in place to do this comment section updating, then it would be more palatable. I think thats probably planned once the UI comes out, right Steve? 😉
October 16, 2012 at 2:43 am in reply to: Suggestion: Be able to add metaboxes field to a specific page #288
James McMemberAgreed, the ID would be better. Here is my untested modification to the Piklist CPT class that should support a comma separated value list of page/post IDs to show your metabox in:
public static function register_meta_boxes_callback($arguments)
{
global $post, $pagenow;extract($arguments);
$data = get_file_data($path . '/parts/' . $folder . '/' . $part, array(
'name' => 'Title'
,'context' => 'Context'
,'description' => 'Description'
,'capability' => 'Capability'
,'priority' => 'Priority'
,'order' => 'Order'
,'type' => 'Post Type'
,'lock' => 'Lock'
,'collapse' => 'Collapse'
,'status' => 'Status'
,'new' => 'New'
,'page' => 'Page'
));$types = empty($data['type']) ? get_post_types() : explode(',', $data['type']);
foreach ($types as $type)
{
$statuses = isset($data['status']) ? explode(',', $data['status']) : false;
$pages = isset($data['page']) ? explode(',', $data['page']) : false;if (post_type_exists($type)
&& (!$data['capability'] || ($data['capability'] && current_user_can($data['capability'])))
&& (!$data['status'] || ($data['status'] && in_array($post->post_status, $statuses)))
&& (!$data['new'] || ($data['new'] && $pagenow != 'post-new.php'))
&& (!$data['page'] || ($data['page'] && in_array($post->ID, $pages)))
)
To use this, you would include a ‘Page’ declaration in your meta-box file comment section. For example:
/*
Title: My Meta Box
Description: My cool new meta box
Post Type: page
Capability: editor
Context: normal
Priority: high
Order: 1
Status: published,prequote,repair-quote
Locked: true
New: false
Collapse: true
Page: 37,45,156
*/
James McMember@jason_lane: small bug/typo in your javascript file
$('#piklist-field-add-more-add-button').unbind('click').click(function(event) {
event.preventDefault();
// alert();
You forgot to provide the event argument in the function…
James McMemberRelated to label generation… in the function post_type_labels:
,'view_item' => __('View ' . self::pluralize($label), 'piklist')
should probably be
,'view_item' => __('View ' . self::singularize($label), 'piklist')
James McMember@steve — I have been digging in the source code of piklist to see how you currently support relationships. I remember from your Wordcamp video you mentioning that you have only added one table (piklist_cpt_relate). I see now that that table is for ‘belongs_to’ relationships.
The save_object method in your piklist-form class gives the first hint:
public static function save_object($type, $data, $belongs_to = false)
I see that we have to pass in a post_ID with the form REQUEST:
$ids['post'] = self::save_object('post', $data, isset($_REQUEST['post_ID']) ? $_REQUEST['post_ID'] : false);
Should I build a meta-box field in my CPT similar to this?
piklist('field', array(
'type' => 'text'
,'field' => 'post_ID'
,'scope' => 'post_meta'
,'label' => __('Belongs To Post ID')
,'description' => __('This field will relate this post to another')
));
James McMemberMake it so! MOAR piklist!
James McMemberYes, this fixed it! Thank you.
@jason_lane: Thank you again for posting that information. I am always interested in examples of how people do things. I think thats because I lack much imagination…
James McMember@jason_lane- Thank you for sharing this!
James McMemberAwesome, thanks.
-
AuthorPosts