Template – Retail Locations

Capture and display custom data types

Capture and display custom data types using ICE and More Fields

Building on the concept of category templates which I started with the FAQ template tutorial last week, this tutorial will cover how to capture and display custom fields in a template. What’s more, I’ll go through the step-by-step process of how to implement this using More Fields which is a plugin that “enables you to define post types, which are custom Write/Edit pages that contains a pre-defined set of boxes” that store their data behind the scenes in custom fields. The concepts from this tutorial will be of interest for anyone who:

  • Has multiple categories of blog content with unique data to capture / present. Thumbnail per post, photo of the day or other customized items.
  • Uses Wordpress as a CMS for unique page data types (event calendar, classified ads, business partners, etc)
  • Finds the selection of custom fields from a drop-down to not be the best user interface experience for capturing structured data.

Direct Video Link:http://www.screencast.com/t/2dcpYsSlk

Example Code

The only real code in this template that is unique is the retrieval of data from a custom field using the get_post_meta function.

A single custom field retrieval
Place this example within the loop of an existing category / post template.

<?php $locationPhone = get_post_meta($post->ID, 'locationPhone', true);
if ($locationPhone != '') { ?>
	<div class="locationInfo">
		<h4>Phone Number</h4>
		<?php echo  $locationPhone; ?>
	</div>
<?php } ?>

Full retail location fields
This example is the full loop for use within a category.php file to display the contents of custom fields named: location

<?php if (have_posts()) : ?>
	<?php while (have_posts()) : the_post(); ?>
 
	<h2><?php echo the_title('','',false); ?></h2>
	<?php the_content(); ?>
	<div class="clear"></div>
 
	<?php $locationAddress = get_post_meta($post->ID, 'locationAddress', true);
	if ($locationAddress != '') { ?>
		<div class="locationInfo">
			<h4>Address</h4>
			<?php $locationMapURL = get_post_meta($post->ID, 'locationMapURL', true); ?>
 
			<?php if ($locationMapURL != '') {
				echo  "<a href='" . $locationMapURL . "'>"; ?>
			<?php } ?>
 
			<?php echo  $locationAddress; ?>
 
			<?php if ($locationMapURL != '') {
				echo "</a>";
			} ?>
		</div>
	<?php } ?>
 
 
	<?php $locationPhone = get_post_meta($post->ID, 'locationPhone', true);
	if ($locationPhone != '') { ?>
		<div class="locationInfo">
			<h4>Phone Number</h4>
			<?php echo  $locationPhone; ?>
		</div>
	<?php } ?>
 
	<div class="clear"></div>
 
	<?php $locationHours = get_post_meta($post->ID, 'locationHours', true);
	if ($locationHours != '') { ?>
		<div class="locationInfo">
			<h4>Business Hours</h4>
			<?php echo  $locationHours; ?>
		</div>
	<?php } ?>
 
	<?php $locationWebsite = get_post_meta($post->ID, 'locationWebsite', true);
	if ($locationWebsite != '') { ?>
		<div class="locationInfo">
			<h4>Website</h4>
			<?php echo  "<a href='" . $locationWebsite . "'>" . $locationWebsite . "</a>"; ?>
		</div>
	<?php } ?>
 
	<div class="clear"></div>
 
	<?php endwhile;
 
else : ?>
 
	<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
 
<?php endif; ?>
This entry was posted in ICE, Tutorials, Wordpress. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Chocolate city
    Posted October 12, 2009 at 8:58 am | Permalink

    This plugin works for post if you have a page tied to a category will it also work for pages..?

  2. Posted October 13, 2009 at 7:41 am | Permalink

    While the functions involved would all work with display from a page, you will have to setup a different query loop in order to get the “sub-pages” or whatever elements you are using to store the retail location info.

One Trackback

  1. By The Power of Custom Fields - Idealien Studios on July 20, 2009 at 9:30 pm

    [...] your dreams into reality together! Skip to content HomeServicesPortfolioProjectsBlogAbout « Template – Retail Locations Solving a custom field query quandry [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

  • Help me help you!

    Name: (required)

    Email: (required)

    How can I help?

    Details:

  • What is an Idealien?

    The word Idealien originates from the word "idea" or "ideal" and conveys my principle philosophies of business:
    • I will always strive to build the ideal solution for my clients - if they aren't happy, I'm not.
    • I am always interested in new ideas or ways to solve a challenge more efficiently.

    Pronounced like chameleon
    the more you say it,
    the better it sounds!

    Since building my brand around this concept it has amazed me how many times I hear people say, "The ideal thing to do would be..." and then pick a different course of action. An Idealien solution is one that is:
    1. Cost-effective
    2. Easy to use and maintain
    3. Helps you meet your business goals
    4. Can scale as your business grows
    5. Engages your customers
    When you combine that with the word alien, in reference to the little blue alien which is the base of my branding, you get Idealien!