Just Custom Fields for WordPress

Installation:

  1. Download, unzip and upload to your WordPress plugins directory
  2. Activate the plugin within your WordPress Administration Backend
  3. Go to Settings > Just Custom Fields
  4. Choose Post Type (Standard/Custom) where you would like to edit custom fields
  5. Create Fieldset
  6. Add fields to the fieldset.

Screenshots:

On this screenshot you can see settings page for a “Page” post type. You can create fieldsets and fields inside of it. This page uses WordPress AJAX API, so it updates without any redirects and editing rather quickly.

screenshot 1 423x241 Just Custom Fields for WordPress plugin

You can create field with one of types below:

  • Input text: usual single-line text box
  • Select: usual dropdown list
  • Select Multiple: area which allow you to select multiple options from the list
  • Checkbox: you can add one or multiple checkboxes
  • Textarea: multi-line text field. You can also enable WordPress editor for this field
  • Datepicker: input field with calendar popup to choose a date.
  • Upload media: use this field to create multiple images or files container
  • Fields Group: using this field you can create a “table” of fields. For example you want to attach clients table to a page – you can create fields group with client/phone/email fields. And add them without any HTML

Next screenshot illustrates how fieldset will look on a post edit page. There are usual text box, date picker field and Upload image field (as you can see you can upload many images here).

screenshot 2 327x241 Just Custom Fields for WordPress plugin

Developers also find this plugin very useful. Cause it’s very easy to add their own components and custom fields with their own plugins and even themes using some new hooks. For more details you are welcome to check readme.txt from the plugin package.

Templates usage

To use values from these fields in your theme, you can use usual post meta functions such as:

Let’s give you some examples. For example we create 3 custom fields for the Page with such slugs: price (Input Text), features (Checkboxes/multiple), slide_images (Upload Media / image). To get values in templates you need to call such lines of code inside the loop functions:

$price = get_post_meta($post->ID, 'price', true);   // we get value for input text
$images = get_post_meta($post->ID, 'slide_images', true);  // we get array of images
$features = get_post_meta($post->ID, 'features', true);    // we get array of checked checkboxes

Now when you have variables with data you can print them in the template. For example like this:

<p>Price: <?php echo $price; ?></p>
<p>Features: <?php foreach($features as $feature) echo $feature.','; ?></p>
<p>Images:</p>
<?php if(!empty($images)) foreach($images as $img) : ?>
	<div><img src="<?php echo $img['image']; ?>" alt="<?php echo esc_attr($img['title']); ?>" /></div>
<?php endforeach; ?>

If you need print single image from custom field you can use such code for this:

<p>Image: <img src="<?php echo $images[0]['image']; ?>" alt="<?php echo esc_attr($images[0]['title']); ?>" /></p>

You can read more about using custom fields on codex.WordPress.org: Custom Fields or search more information in google. There are a lot of example on different sites how to use WordPress custom fields. Our plugin just make easy interface to edit them in administration panel, and you can use all build-in WordPress functions for custom fields.

Template functions for Upload Media type “Image”

Since i’ve posted my plugin i had a lot of comments about “How to use Upload Media field in templates”. When I develop this plugin I wanted make life easier for developers. But a lot of people with pure PHP knowledge found it useful. So I decide to make few templates functions for people who are not familiar with PHP.
These functions are available since version 1.3:

  • just_custom_image( $post_id, $field_slug, [$args_single] );
  • just_custom_images_list( $post_id, $field_slug, [$args_multiple] );

These functions take care about PHP routine and just print image or images list. Function params are:
$post_id – your post ID
$field_slug – your meta field slug
$args_single – array of additional params you may want to use. Available keys are:
* ‘before’ (html to insert before image tag, default: none),
* ‘after’ (html to insert after image tag, default: none),
* ‘width’ (image width attribute value, default: none),
* ‘height’ (image height attribute value, default: none),
* ‘echo’ (print html or just return, default: true)
$args_multiple – array of additional params you may want to use. Available keys are:
* ‘before’ (html to insert before images list, default: ‘<ul>’),
* ‘after’ (html to insert after images list, default: ‘</ul>’),
* ‘before_item’ (html to insert before images list item, default: ‘<li>’),
* ‘after_item’ (html to insert after images list item, default: ‘</li>’),
* ‘width’ (image width attribute value, default: none),
* ‘height’ (image height attribute value, default: none),
* ‘echo’ (print html or just return, default: true)

Let’s try few examples.
Example 1: print single image:

	just_custom_image($post->ID, 'slide_images');

Example 2: print single image wrapped with <div> tag and has width/height set to 100px:

	just_custom_image($post->ID, 'slide_images', array(
		'before' => '<div>',
		'after' => '</div>',
		'width' => 100,
		'height' => 100,
	));

Example 3: print list of images

	just_custom_images_list($post->ID, 'slide_images');

Example 3: print list of images based on DIV tags

	just_custom_images_list($post->ID, 'slide_images', array(
		'before' => '<div>',
		'after' => '</div>',
		'before_item' => '<div>',
		'after_item' => '</div>',
	));

Download

Our plugin is available for download:

download Just Custom Fields for WordPress
or
download from WordPress.org repository

DONATION

The script is free for use, but if you want to support the script author by donating some $$$ please use the form below, thanks in advance.

滚动至顶部