28
November 18, 2012

Custom Fields & Custom Metaboxes Overview

Embed Size (px)

DESCRIPTION

Sallie Goetsch provides an overview of custom fields and custom metaboxes in WordPress at the November 2012 East Bay WordPress Meetup. (These are the slides that never reached Oakland.)

Citation preview

Page 1: Custom Fields & Custom Metaboxes Overview

November 18, 2012

Page 2: Custom Fields & Custom Metaboxes Overview

EastBayWP.com

Page 4: Custom Fields & Custom Metaboxes Overview

Ongoing Sponsor: Page.ly

http://page.ly/

Page 5: Custom Fields & Custom Metaboxes Overview

Today’s Sponsor

http://www.woothemes.com/

Page 6: Custom Fields & Custom Metaboxes Overview

Intro to Custom Fields

& Custom Metaboxes Sallie Goetsch

November 18, 2012

Page 7: Custom Fields & Custom Metaboxes Overview

CUSTOM FIELDS http://codex.wordpress.org/Custom_Fields

Page 8: Custom Fields & Custom Metaboxes Overview

What Is a Custom Field?

“Arbitrary extra information”—not part of your regular post or page content

Page 9: Custom Fields & Custom Metaboxes Overview

What Can You Put in a Custom Field?

ANYTHING

• Text

• Images

• Media

• Embed codes

• Links

• Dates

Page 10: Custom Fields & Custom Metaboxes Overview

How Do I Add Custom Fields?

• Right in your post or page UI, below the content box.

Page 11: Custom Fields & Custom Metaboxes Overview

Don’t See them? Check Screen Options

Page 12: Custom Fields & Custom Metaboxes Overview

How Do Custom Fields Work?

• KEY, a.k.a. NAME: The name of the custom field

• VALUE: The content of the custom field

Page 13: Custom Fields & Custom Metaboxes Overview

How Does WP Store Custom Fields?

Page 14: Custom Fields & Custom Metaboxes Overview

How Do I Display Custom Fields?

THE BASIC WAY

<?php the_meta(); ?>

within the loop will display the key, followed by the value.

http://codex.wordpress.org/Template_Tags/the_meta

Page 15: Custom Fields & Custom Metaboxes Overview

Displaying Custom Fields, with Parameters This Time

<?php get_post_custom_values

($key, $post_id); ?>

Lets you choose which custom fields to display.

Page 16: Custom Fields & Custom Metaboxes Overview

Displaying Custom Fields in Genesis Themes

if( $post->post_content != "" ) {

echo "<div class='testimonial-story'>";

echo "<h3>How the WLC System Worked for " . genesis_get_custom_field( 'wlc_success_name' ) . "</h3>";

the_content( __( '[Read more...]' , 'genesis' ) );

echo "</div>";

}

Page 17: Custom Fields & Custom Metaboxes Overview

CUSTOM METABOXES http://codex.wordpress.org/Function_Reference/add_meta_box

Page 18: Custom Fields & Custom Metaboxes Overview

What’s a Metabox?

Also known as a “write panel,” a “metabox” is one of those nice little boxes in the back end of WordPress that you use for entering or controlling content.

Metaboxes let you use radio buttons, date pickers, file uploads, and other handy UI elements that custom fields don’t. They make life easier for your clients.

Page 19: Custom Fields & Custom Metaboxes Overview

Function: add_meta_box

<?php add_meta_box

( $id, $title, $callback,

$post_type, $context,

$priority,

$callback_args ); ?>

Page 20: Custom Fields & Custom Metaboxes Overview

Code for a Twitter Metabox

Page 21: Custom Fields & Custom Metaboxes Overview

What That Metabox Looks Like

Page 23: Custom Fields & Custom Metaboxes Overview

If You Don’t Want to Code…

http://wordpress.org/extend/plugins/types/

Page 24: Custom Fields & Custom Metaboxes Overview

Metaboxes Created by Types Plugin

WYSIWYG

URL

Multiple Lines

Page 25: Custom Fields & Custom Metaboxes Overview

Display by API

Page 26: Custom Fields & Custom Metaboxes Overview

Display as Normal Custom Fields

// display speaker bio

echo "<h3>About the

Speaker</h3>";

echo "<div class='speaker-

bio'>";

echo "<p>" .

genesis_get_custom_field( 'wpcf-

speaker-bio' ) . "</p>";

Page 28: Custom Fields & Custom Metaboxes Overview

More Stuff

As always, you’ll find links to related resources, plus a copy of these slides, on the EastBayWP.com site.

You can find me, your humble presenter and harried meetup organizer, @salliegoetsch on Twitter or at WPFangirl.com.