下载 more-fields.zip

http://wordpress.org/extend/plugins/more-fields/

1. Options -> More Fields

The required boxes are set up in Options->More Fields.

Description of fields:

  • Title of box - This is the title at the top of a box - appearing on the blue background on the Write/Edit page. This title is also used when accessing the content of a box in a template.
  • Settings:
    • Include this box on the Write/Edit page - toggles whether or not this box is shown on the Write/Edit page.
    • Position left (else right)- sets the position of the box in either the left, or the right column. If positioned on the left, the box will be much larger than if positioned on the right. Having it positioned on the left is more appropriate when having textareas that are to contain lots of text.
    • Delete this box! - Removes this box from from the Options page and the Write/Edit page. The box will no longer be shown using the template function get_box(); . The settings must be saved (Update Settings) for the box to be removed.
  • Title - Sets the title for the field. This value is optional, which might be handy when creating a box with only one field, such that the title of the field really is the title of the box.
  • Key - This field is required. It is the name of the Custom Field that is created for this field. Using this key, a field can be echoed in a template using e.g. meta(key);.
  • Options - This sets the input type of the field. The following types of options are available:
    • blank - the default type of a one line textfield is created by leaving the Options field empty.
    • textarea - This creates a multi-line textarea.
    • E.g. 0:10 - Creates a select list with values between 0 and 10 in ascending order.
    • E.g. 10:0 - Creates a select list with values between 10 and 0 in descending order.
    • E.g. value1, value2, value3 - Creates a select list with values value1, value2 and value3.

Using the controls to the right of the field, it can be moved up or down in the list. The order that the fields appear in on this page is the order that they are returned in when using the get_box(); function

2. Template functions

There are currently two template functions supplied in this plugin.

  1. meta($key) - echoes the Custom Field with key $key.
  2. $var = get_meta($key) - returns the Custom Field with key $key.
  3. The more_fields action, prints out the entire content of a box.
3. Examples
3.1 Example one: Employee/member information

If you have company or organization and wisely opted for using WordPress as the CMS, then you could create a page per employee/member (if you have a reason for doing so — this is mere conjecture). Say you want to create pages for this (as opposed to a post), one page per person.On the Write->New Post page, a section similar to this could be added:

WordPress自定义字段插件More Fields 0d2524a37a579dc5f384df6539dafff1 thumb

This is created the following way in Options->MoreFields:

WordPress自定义字段插件More Fields 34c3fd5a9d4fb1c8181990713906861e thumb

Note that the Position Left tickbox is checked and that the Show in Post Write/Edit is unticked. This box will only appear when adding or editing a Page.If you want to display only the biography in a page template:

<?php meta('ci_bio'); ?>

And you can store the value of the custom field to a variable using get_meta, e.g.:

<?php
  if ($bio = wptexturize(get_meta('ci_bio')))
  echo 'Resume: ' . $bio;
?>

Or to display this information as a ‘ul’ list with a ‘h3′ header inside a div called ‘employee_info’:

<?php
   $options = array('div' => 'employee_info');
   do_action('more_fields', 'Employee info', $options);
?>

If you still only want to display the bio, use the ’show’ keyword in the options.

<?php
   $options = array('div' => 'employee_info', 'show' => 'ci_bio');
   do_action('more_fields', 'Employee info', $options);
?>

Or, to only show the name and the position id a ‘dl/dt/dd’ list, with a ‘h3′ header:

<?php
   $options = array('div' => 'employee_info', 'format' => 'dl', 'show' => array('ci_name', 'ci_position'));
   do_action('more_fields', 'Employee info', $options);
?>
3.2 Example two: Geocaching/Geographical information

If you are a member of the geocaching community, then a blog post about a specific hunt for a geocache would require additional fields for latitude and longitude. On the admin page, something like this can be created:

WordPress自定义字段插件More Fields cba30f09be9c8633eff9262ebdbffc42

On the Options->More fields page, this is created in the following way:

WordPress自定义字段插件More Fields a6a12802c61bd7d63f3299b888f59a25 thumb

This can then be printed in a template as a dl/dt/dd list, inside a div called ‘geocaching’, by calling the following:

<?php
   $options = array('format'=>'dl', 'div'=>'geocaching');
   do_action('more_fields', 'Geocaching', $options);
?>

If you want to create a link to google maps (other brilliant map services are available, like Multimap)

<a href="http://maps.google.com/?ll=<?php meta('gc_latitude'); ?>,<?php meta('gc_longitude'); ?>">Google Maps</a>

The key that I’m supplying to the meta function is the key that i specify in the More Fields Options.

3.3 Example three: Wine blog

Say you’re writing about wine - and we all love wine, right? Additional information about the bottle of wine that is being written about will add value to the post - information such as grape, winery, and perhaps a score. One could construct a box in the admin like this:

WordPress自定义字段插件More Fields 0c352a7101cd8e39a7e53db22ce045c5

I’ve filled it in just highlight that we’re creating selects. The setup in the More Fields Admin looks like this:

WordPress自定义字段插件More Fields 1e8d0f5965d74c28054a690646bf6301 thumb

Note that the Year range runs from 2007 to 1970 such that 2007 is listed first. The Score is a select between 1 and 10.

To retrieve the specifics about a wine reviewed in a post:

 <?php do_action('more_fields', 'Wine');?>

Or, to create a link to a page with one of the fields a as a parameters:

<a href="http://en.wikipedia.org/wiki/<?php meta('wine_type'); ?>">Wikipedia</a>

This method can be useful creating links for an affiliate program (e.g. Amazon Affiliate Program), generating revenue for your site. These affiliate links often include a search term, which could make the link relevant for your post.

3.4 Example four: Post specific CSS

By inserting CSS in the head of your templates you can alter the design of your WordPress site on a post by post basis.

To create a field on the Write/Edit page where this can be inserted, configure More Fields in the following way

WordPress自定义字段插件More Fields 91dfafe391bcaefa3d17c0e7e10af305 thumb

Then, within the <head> tag of of your templates, insert this code:

<?php meta('extra_css'); ?>

For examples of this in use see this special on disco, compared to the normal look of the site.

4. Advanced use

More Fields provides an action: more_fields_admin when the plugin enters the building of the content of a widget, i.e. after the head with the title is built. You can use this to insert html, like special fields, e.g. based on the content of the post.A simple example using the above geocaching example - executing some javascript when a box is checked:

function p2m_meta_insert ($title) {
   if ($title == 'Geocaching') {
      echo '<input οnchange="doSomething();" type="checkbox" /> Cache found?';
   }
}
add_action('more_fields_admin', 'p2m_meta_insert');

Which will change the top of the box to this:

WordPress自定义字段插件More Fields 937138e2601e50afa104fe8d8b7c1229

The JavaScript is inserted using the admin_footer action.At dagensskiva.com we use the more_fields_admin action to insert a checkbox used to indicate whether a review is the review of the day one or an additional one. This tickbox triggers JavaScript that updates the post with the appropriate categories. We also insert three small select boxes (year, month and day), that enables the writer to set the date that the post will be the daily review for - this changes the timestamp settings, again, using JavaScript.

5. Language support

The .po file for the plugin can be found in its directory. Name compiled .mo files as e.g. p2m-more-fiels-sv_SE.mo where ’sv_SE’ is the language domain (here Swedish), and place in the same directory as the rest of the plugin files.

As of yet, the plugin is only translated from English into shoddy Swedish.

6. License

The More Fields WordPress plugin is relased under GPL, and the following license can be found in the header of more-fields.php.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.You should have received a copy of the GNU General Public License along with this program. If not, see

Incoming search terms: