Forum Replies Created

Viewing 15 posts - 31 through 45 (of 47 total)
  • Author
    Posts
  • in reply to: Suggestion: Be able to add metaboxes field to a specific page #428
    James Mc
    Member

    Here 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…

    in reply to: Suggestion: Be able to add metaboxes field to a specific page #425
    James Mc
    Member

    @kattagami: if I have some time this weekend I’ll look into implementing this for you.

    in reply to: field type: slider #373
    James Mc
    Member

    Sweet, looking forward to it.

    in reply to: field type: slider #371
    James Mc
    Member

    Thanks for this. I hope Sandy didn’t wash Steve and Kevin away!

    in reply to: Taxonomies, custom post statuses, and wp_tag_cloud() #300
    James Mc
    Member

    @Sarah: I’ve noticed that custom post statuses don’t appear in the quick edit status menu as well.

    in reply to: Suggestion: Be able to add metaboxes field to a specific page #296
    James Mc
    Member

    Now that seems look a good idea and compromise. Also, its a feature that lends itself to interesting options for theme designers.

    in reply to: Suggestion: Be able to add metaboxes field to a specific page #293
    James Mc
    Member

    @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? 😉

    in reply to: Suggestion: Be able to add metaboxes field to a specific page #288
    James Mc
    Member

    Agreed, 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
    */

    in reply to: media upload #281
    James Mc
    Member

    @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…

    in reply to: Bug in post/taxonomy label generation #280
    James Mc
    Member

    Related 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')

    in reply to: Custom Post Type Relationships #279
    James Mc
    Member

    @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')
    ));

    in reply to: Custom Post Type Relationships #273
    James Mc
    Member

    Make it so! MOAR piklist!

    in reply to: Bug in Custom Post Type Settings Tabs #269
    James Mc
    Member

    Yes, 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…

    in reply to: media upload #268
    James Mc
    Member

    @jason_lane- Thank you for sharing this!

    in reply to: Suggestion/Request: jQuery Tabs #254
    James Mc
    Member

    Awesome, thanks.

Viewing 15 posts - 31 through 45 (of 47 total)