homepage Welcome to WebmasterWorld Guest from 54.197.108.124
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / WordPress
Forum Library, Charter, Moderators: lorax & rogerd

WordPress Forum

    
Best Way to Structure Data in Wordpress
rogerd




msg:4442048
 4:26 pm on Apr 17, 2012 (gmt 0)

OK, WP experts... whats the best way to add data structure to a Wordpress site? For example, imagine I blog about travel, and now I want to do hotel reviews. I could just free-form the review as all text, but say I wanted to add some structure - the hotel name, its address, phone, and a rating and text comment for categories like "service" and "room size."

Adding structured data fields would be good, as it would make it easy to compare different hotels, and also, I suppose, microdata elements could be appended to help Google sort out what those fields meant.

So, what's the best way to do something like this?

 

lorax




msg:4442058
 4:48 pm on Apr 17, 2012 (gmt 0)

If I understand you correctly, you could use Custom Fields. You could use a plugin like the one below or edit your theme and database to add them in on your own.

[wordpress.org...]

Then with a bit of custom programming you could query for the data and present it in a custom page.

rogerd




msg:4446158
 6:56 pm on Apr 26, 2012 (gmt 0)

Looks like a possible path, thanks.

rlange




msg:4459580
 7:06 pm on May 30, 2012 (gmt 0)

It sounds like a custom post type [codex.wordpress.org] might be the ideal solution, but it's quite a bit more involved than a plugin. There are plugins available to help you create a custom post type, though.

--
Ryan

rocknbil




msg:4459938
 3:48 pm on May 31, 2012 (gmt 0)

I do these in one of two ways. Which I choose depends on what is going to be easiest for the non-tech savvy owner who will maintain the site, because that's really the point of a CMS. :-)

- Child documents. Sometimes it's easier to structure it as child documents. For example, if a site has a locations page with multiple locations, I'll make each page a child of the visible locations page. Each child has a simple "block" containing the address/phone info, and may or may not have custom fields with Google Map data, either a full code URL or just the coordinates.

The advantage to this is that data can be pulled for other areas of the site; for example, if the location bits are used in a global footer, a short function pulls it from child_of [the id of locations].

This requires a little custom coding and a custom coded menu, or some plugin that allows you to selectively pick resources that appear in menus.

- As mentioned, sometimes it's easier to place this data in custom fields. This also might require a little custom coding.

For both of these, centralize your code - put functions with a return value you need in functions.php and structure it so when you need to get this info, you just call the function.

echo get_footer_locations_data($locations_parent_id);

echo get_location_page_data($post->ID); // on the locations page itself

echo get_custom_menu(1,24,35,67,123); // ID's of main menu items, for example

For this last one, a better way is to have a custom field "include_in_top_menu" on every page you want in the menu, then use that field to determine which items appear in the menu. This puts the control of that back in the hands of the Wordpress admin.

Or, you could look for plugins - somehow it seems more efficient to write a 20-30 line function that will remain stable through all updates and not require frequent updates, like a plugin might.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / WordPress
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved