Viewing 12 reply threads
  • Author
    Posts
    • #853

      I am currently setting up a Pedigree CPT. The pedigree fields on the post edit screen need to have a specific table type layout and I need to remove the piklist-label-container. Any help on how I can achieve this would be appreciated:

      Pedigree Edit Screen layout

    • #854
      jchamb
      Member

      @txhorselady. If i’m taking the correctly you should be able to hook up a custom template with out a label, and then add it to your field. Here is an example.

      In your functions.php add

      add_filter('piklist_field_templates', 'add_piklist_field_templates');
      
      function add_piklist_field_templates($templates)
      {
      	$templates['no_label'] = '[field_wrapper]
      		                          <div id="%1$s" class="%2$s">
      		                              [field_description_wrapper]
      		                                  <small>[field_description]</small>
      		                              [/field_description_wrapper]
      		                              [field]
      		                          </div>
      	                          [/field_wrapper]';
      
      	return $templates;
      }

      and then in your meta-box file

      piklist('field', array(
          'type' => 'group'
          ,'field' => 'my_group'
          ,'add_more' => true
          ,'label' => ''
          ,'description' => ''
          ,'template' => 'no_label' // custom template to not add label wrap
          ,'fields' => array(
              array(
              	'type' => 'textarea'
              	,'field' => 'column_1'
              	,'label' => 'Column 1'
                  ,'columns' => 6
              )
              ,array(
              	'type' => 'textarea'
              	,'field' => 'column_2'
              	,'label' => 'Column 2'
                  ,'columns' => 6
              )
          )
      ));
    • #855

      cool … I will give that a try. I was trying to insert an image of what I want but I can’t seem to get it to load on the screen. Here is another try

    • #859

      Is there a way that I can use a table to lay this out in the admin area?

    • #860

      Never mind …. I figured it out Woo Hoo!!! I love Piklist

    • #861

      OK, so I’m having a bit of trouble returning the field values on the front end. Here is the result of my code for the backend:
      Pedigree

      I used a bit of css to hide the unnecessary fields for this bit of code (to save space here I only pasted the code for the first row):

      piklist(‘field’, array(
      ‘type’ => ‘group’
      ,’field’ => ‘mhs_pedigree’
      ,’position’ => ‘start’
      ,’template’ => ‘no_label’ // custom template to not add label wrap
      ,’fields’ => array(
      //row 1
      array(
      ‘type’ => ‘text’
      ,’field’ => ‘spacer1′
      ,’label’ => __(‘.’)
      ,’columns’ => 4
      ,’position’ => ‘start’
      ,’attributes’ => array(
      ‘class’ => ‘mhs_spacer’
      )
      )
      ,array(
      ‘type’ => ‘text’
      ,’field’ => ‘spacer2′
      ,’label’ => __(‘.’)
      ,’columns’ => 4
      ,’attributes’ => array(
      ‘class’ => ‘mhs_spacer’
      )
      )
      ,array(
      ‘type’ => ‘text’
      ,’field’ => ‘mhs_c3-1′
      ,’label’ => __(‘C3-1′)
      ,’value’ => ‘C3-1′
      ,’columns’ => 4
      ,’position’ => ‘end’
      )
      )
      ));

      and so on …..

      I am unable to put the individual values in my post template using this code:

      <?php echo get_post_meta($post->ID, ‘mhs_pedigree[mhs_c1-1]’, true);?>

      What am I doing wrong? Each mhs_c?-? field will be placed in respective table cells on the front end.

    • #862
      Steve
      Keymaster

      @txhorselady– The first thing you should do is see how WordPress is saving the values. Something like this will help you visualize the data:`$meta = get_post_custom($post_id);
      print_r($meta);`

      Once you see the output, you can grab it properly.

      This is standard WordPress, using a standard WordPress function… Piklist doesn’t do anything accept help you create the field easily. That’s one of the things that makes Piklist awesome.

    • #865

      Pardon my ignorance but I’m still learning PHP. Here is the result for that row and I’m not sure how to extract only the mhs_c3-1 value

      [mhs_pedigree] => Array ( [0] => a:3:{s:7:”spacer1″;s:0:””;s:7:”spacer2″;s:0:””;s:8:”mhs_c3-1″;s:10:”grand sire”;} )

      Would there be a better way of laying out the admin screen to achieve the result that I need?

    • #866
      jchamb
      Member

      looks like the data is serialized. not sure what your current call looks like but once you have that array as a variable with that exact array structure you can do this

      $mhs_pedigree = unserialize($mhs_pedigree[0]);

      $mhs_pedigree should then be an array of individual values as an array.

    • #867

      Now I am lost as to what to do with that bit of code

    • #868
      jchamb
      Member

      Sorry I was assuming you knew that the array was showing from what steve posted. Example step by step, starting from what Steve posted.

      $meta = get_post_custom($post_id);
      Then when you do the print_r you should see an array that looks something like you posted

      Array (
          [mhs_pedigree] => Array ( [0] => a:3:{s:7:”spacer1″;s:0:”";s:7:”spacer2″;s:0:”";s:8:”mhs_c3-1″;s:10:”grand sire”;} )
      )

      So $meta is now equal to an associative array that contains the key ‘mhs_pedigree’. mhs_pedigree is equal to another array which the first value (0) is serialized data.

      Basically what happens is when the data is saved by wordpress it takes your group piklist field, and creates and meta value, now for each field inside of that group it takes all of them as an array and runs php’s serialize function on them to create a single string of data. essinitally making your group field equal to a string.

      Okay, back to how you can use this. You need to be able to access each field’s value back individually from your mhs_pedigree, so lets follow the array down to the serialized data and convert that back to an array of data you can use.

      // Grab all of our custom post types
      $meta = get_post_custom($post_id);
      
      // turn mhs_pedigree into its own array.
      $mhs_pedigree = unserialize($meta['mhs_pedigree'][0]);
      print_r($mhs_pedigree);

      now the printed screen values should show something along this line (based on your fields)

      Array (
          [spacer1] => 'some_value',
          [spacer2] => 'some_value',
          [mhs_c3-1] => 'some_value
      )

      so to use those in your template then now you can user

      <?php echo $mhs_pedigree['mhs_cs-1']; ?>

      just note that i didn’t test anything, just trying to provide a rough example to explain what your seeing.

    • #870

      Woo Hoo …. You are so awesome!!! Thank you very much.

    • #871
      Steve
      Keymaster

      Nice explanation @jchamb!

Viewing 12 reply threads
  • The topic ‘Grouped Fields Layout’ is closed to new replies.