WordPress Customization
By Justin Laing
2008-01-09
Meta Data / Custom Fields For Page Customization

Meta data can be added to any blog post or page. It’s located under the
edit box on the Write Post and Write Page sections of the admin
interface. Look for the section called “Custom Fields”, that’s your
post meta data. Each piece of meta data has a key and a value. You can
use meta data to store almost anything, and you can retrieve it within
the page using some template functions/tags. Here some code I use so
that each page can have a custom title, description, keywords, and
style rules. This code is placed within my <head></head>
tags in my header.php file:

The first section of the code loads the meta data. For example to get the title meta data I call $title = get_post_meta($wp_query->post->ID, “title”, true);. I can then use the $title variable within my code to display the title information I retrieved. The styles meta data I retrieve is a little
more complex because it is grabbing an array of styles. So if there are
more than one meta data elements with the title “style” I will get all
these styles within one array. The last parameter of get_post_meta
determines if an array is to be returned or just single value. I loop
through the array and display each style using this code: <?php foreach ($styles as $s) echo $s . “\n”; ?>.
Tutorial Pages:
»
Introduction To WordPress
»
WordPress Themes
»
Structure Of A WordPress Theme
»
Making Your New Theme
»
Modifying The Header
»
Blog / Post Templates
»
The Post Loop
»
Page Templates
»
Sidebars
» Meta Data / Custom Fields For Page Customization
Originally posted on Makebeta
|

|