Tagged: 

Viewing 25 reply threads
  • Author
    Posts
    • #276
      kattagami
      Member

      Hello,

      I would like to suggest you for a futur release of Piklist the possibility to target a specific page with its slug to add a bunch of metaboxes in a specific way only for this page.

      The header code snippet would look like this:

      /*
      Title: My Demo Meta Box
      Post Type: page ‘slug’
      */

    • #283
      Steve
      Keymaster

      @kattagami– This is a great idea, and I just added it to our list of todo’s. We’re thinking using the ID instead of the SLUG, since Slugs can change.

    • #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
      */

    • #290
      kattagami
      Member

      I’m agree with you, Slug can change but using the ID implie to know the ID in advance, right ?

      Now imagine this situation:

      When I activate my theme, I decide to automaticly create a new page. When I code this creation, I can decide the Slug but not the ID.
      If I want to set some specific metaboxes for this new page (at the same time, during the theme activation), how can I know wich ID indicate in the file comment section ?

    • #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? 😉

    • #295
      kattagami
      Member

      And instead of target an ID or a Slug in the file comment section, why not target a custom template ?


      /*
      Title: My Meta Box
      Post Type: page
      Template: my_custom_template
      */

      I set specific metaboxes for a custom template (custom template label not change) and then when I create a page (manualy or by code) I can choose the right template (manualy or by code) to set my specific metaboxes to my pages.

    • #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.

    • #298
      Steve
      Keymaster

      @James Mc– Thanks for the code! Works great. You don’t even have to specify POST TYPE, just ID. Kevin and I will discuss get back to you.

      As for UI, we have some fun things in store, which will help this workflow a bit.


      @kattagami
      – Page Templates really change the workflow. We’ll definitely get back to you both on this.

    • #303
      Kevin
      Keymaster

      Thanks for the great ideas guys, I think am am really excited about the page template idea. I would love to see meta boxes respond to the select box changing… this has been put on our radar 😉

      I will also be adding some filters to these sections to allow deeper customizations on not only how meta boxes are rendered but settings/term meta/user meta/media meta as well.

      More to come,

      Kevin

    • #305
      Jason Lane
      Member

      I’ve done this kind of thing before, but where the metabox was for a specific category. I found a simple tutorial online, and I’m sure it could easily be adapted to work in Piklist, and related to pages or templates instead of categories. The basic method is to allow the metaboxes to be added/created unconditionally, and then to simply use JS to hide/show the boxes as required. The tutorial is here.

      In my implementation, I simply added a settings field to the theme options to allow selecting which category to apply the metabox to.

    • #403
      Steve
      Keymaster

      This has been added to v0.6.7. Just use ID in the comment block:

      ID: 2

      Thanks for the suggestion!

    • #424
      kattagami
      Member

      Thanks Steve for this improvement.

      In this thread, we spoke about the possibility to use the Template Page. Do you plan to implement this feature in the next Piklist update ?

    • #425
      James Mc
      Member

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

    • #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…

    • #433
      kattagami
      Member

      Wow awsome, thanks James, it’s very cool of you.
      I will give your code a try.

      Hope your code would be intergated in futur version of Piklist 🙂

    • #518
      James Mc
      Member

      @kattagami — Did it work for you? I guess it would fancier to have some css and javascript added to this so that template specific meta-boxes are hidden until the corresponding template is selected.

    • #697
      lobsterman
      Member

      I would also like to see  @James MC’s solution integrated into the core. It worked so well I forgot about it till updating piklist broke it.

    • #702
      James Mc
      Member

      I’ll try emailing in a SVN patch this weekend.

    • #1285
      chan
      Member

      Has this featured been added yet. This would be an important feature to have to be able to target specific page templates.

    • #1288
      Steve
      Keymaster

      @chan– This works on v.0.80 beta. However, the meta box will not show/hide when you initially select the page template. You will need to save the page for the hide/show to take effect.

      Template: my-template.php

    • #1318
      James Mc
      Member

      Its been a crazy summer and fall for me, but I’m back and will likely be building with Piklist again in the near future. Thanks for the 0.9.0 release. I feel like I’ll have to start all over again. Will look into making the page template specific metaboxes responsive.

      James

    • #1323
      Steve
      Keymaster

      @james_mc– Glad you’re back. 😉

    • #4098
      aazcast
      Member

      Hi,

      this is working on the version 0.9.4.27?

      i try it… but is not working.

    • #4115
      Steve
      Keymaster

      @aazcast– Welcome to the Piklist community!

      Which feature isn’t working? ID, TEMPLATE or another?

      • #4117
        aazcast
        Member

        Hi Steve.

        I am using Template ex:

        Template: my template.php

        Thanks.

    • #4118
      Steve
      Keymaster

      The Template parameter is the file name of the template WITHOUT “.php”:

      Template: my-template

      See this doc for reference >

      Let us know if that works for you.

    • #4159
      Steve
      Keymaster

      Closing this ticket. Let us know if you need any more help.

Viewing 25 reply threads
  • The topic ‘Suggestion: Be able to add metaboxes field to a specific page’ is closed to new replies.