Translations of this page:

Please note - this is simply a Google Translation from the original Spanish, so the screenshots are not yet translated.

Working with groups, duplicate groups and duplicate fields

Magic Fields to create groups of fields (Custom Fields) in this way we can separate fields (Custom Fields) and have a better handle on the fields..

Fields that are not in a group are placed inside the box “Magic Fields Custom Fields.”

Groups

To create a page where we add a button field with + Create a Group.

Once in the Options page of the group we have the fields: Name (group name) and Duplication (option that can replicate group, a feature that will try later)

Once we created the group back to the page to add fields, but we'll see our group created

To edit the group we click on the name of group.For add a field to the group we click on the “crate field” before the name of the group.

The creation of the field in a group is the same as if we create a field without a group.

On the Write Panel field see what groups have been created and which fields belong to each group.

and creating an element of what we would see our Write Panel as follows:

How to display this information in the fields in the template is the same as with no field group, using functions such as get, get_image, gen_image or get_audio. to see all the options on these works read Funciones de Front-end

Duplicate Group

Feels Magic has the option to duplicate a group (doubles all fields in a group). We can see the usefulness of this feature with the following example: we need a Write Panel where we have members of the company.

Write Panel create a page type called “Team”, the panel will write only one (single) created a group called “member” and the options selected group the group is duplicated (The group Can Be duplicated).

once created the group added to the group the following fields:

  • Name: a textbox field with the name: nombre_miembro label: Name of member
  • Occupation: textbox field with the name: puesto_miembro label: As Member
  • Photo: an image field with the name: foto_miembro label: Photo of the limb (additional options Max Height: 150, Max Width: 100 and Custom: zc = 1)

Our fields must be as follows:

Now we post the item (remember that is unique). see our group box, fill the fields with data from our first member. To duplicate the image you click on the + in the lower right side (we can duplicate the group as often as necessary.)

observe that the group was duplicated with all fields of the group. Now we can fill the fields for a new member. doubled for this group see in the lower right side to put a link labeled “Remove Group” with this link we can delete the group.

One of the best features of the duplicate groups is that we can sort the groups than doubled. we accomplish this by clicking and dragging on the image as a cross in the bottom left of the group. See video. this feature and use the Front-end functions can show in that order duplicate groups.

We have two ways to display the groups in the template. in our template add the following code (in our case will be in page.php)

<?php
   // duplicate groups.
 
   // getGroupOrder us back an array of the order of groups
   // The parameter for this function is the name of a field belonging to the group
   $miembros = getGroupOrder('nombre_miembro');
   foreach($miembros as $miembro){
      // the second parameter of the function and get_image get is the index of the group to show
      echo get('nombre_miembro',$miembro)."<br />";
      echo get('puesto_miembro',$miembro)."<br />";
      echo get_image('foto_miembro',$miembro)."<br /><br />";
   }
?>

The second method is to use the get_group function.

<?php
  // second way to get the fields
 
  // get_group we return an array with all groups and fields of the group
  // the parameter to this function is the name of the group
  $miembros = get_group('miembro');
  // to see how this made the arrangement can use pr($miembros);
  // the way this arrangement is made
  // [index of the group] [field name] [index of the field]
  // for fields image type level but in accordance with the letter "o" to the original image or "t" for thumbnail
  foreach($miembros as $miembro){
    echo $miembro['nombre_miembro'][1]."<br />";
    echo $miembro['puesto_miembro'][1]."<br />";
    echo "<img src='".$miembro['foto_miembro'][1]['t']."'><br /><br />";
  }
?>

In both cases the result is as follows:

We can change the order of duplicate groups and observe the new order is respected on our site (without changing the code) See video

For more information about all parameters of the functions get and read the section get_image Funciones de Front-end

Duplicate Fields

Duplicate fields work similarly to duplicate groups.

Show the operation of the duplicate fields with another example, we created a Write Panel (in this case the call record) in the Write Panel add a textbox field (name, song, label: Name of the song) is important to specify that the field can duplicate (Can Be duplicated).

After adding the duplicate field we click on new menu for our write panel. notice that under our field is a link marked ”+ Duplicate” this link is used to duplicate the field.

fill the field and add a duplicate field we click ”+ Duplicate”, we can double the field as often as necessary.

When we notice two things duplicate fields for duplicate field below link appears with the caption ”- remove” this serves to clear the field and before the name of the field is a (number) This field indicates the number of replacement (after saving / update the post / page ordered agree to this index)

Now we see two possible ways to display these fields in our duplicate template, in this case as the write post panel type was edit the single file of our theme:

using getFieldOrder and get

<?php
  // form 1, using getFieldOrder and get
 
  // the function returns an array getFieldOrder us to index field
  // The parameter for this function is the name of the field
  $canciones = getFieldOrder('cancion');
 
  foreach($canciones as $cancion){
     // get the first parameter is the name of the field, the second is the index of the group, if this
     // field is not duplicable placed in a group 1, the third parameter is the index of field
     echo get('cancion',1,$cancion)."<br />";
  }
?>

The second way is using get_field_duplicate function.

<?php
  // form 2, using get_field_duplicate
 
  // the function returns an array get_field_duplicate us all duplicates of the field
  // this function has as its first parameter the name of the field and a second optional parameter
  // with the index group (if the group is doubled)
  $canciones = get_field_duplicate('cancion');
 
  foreach($canciones as $cancion){
     echo $song."<br />";
  }
?>

Of the two forms is the result is the following:

To learn more all the parameters of the functions get, and getFieldOrder get_field_duplicate read our section Funciones de Front-end.

Notes

After seeing how groups work, field duplicates and duplicate groups can create the combinations we need. we can write in a panel with fields without a group we can create all the groups (duplicated or not) we need, we can create a duplicate field within a group or no group. We have a duplicate field in a duplicate set and display information through the parameters of the functions of front-end (to know all the parameters of these functions reads the section Funciones de Front-end)

dealing_with_groups_duplicate_groups_and_duplicate_fields.txt · Last modified: 2011/07/02 00:36 (external edit)