Welcome to WebmasterWorld Guest from

Forum Moderators: rogerd & travelin cat

Message Too Old, No Replies

Best Way to Structure Data in Wordpress



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

WebmasterWorld Administrator rogerd is a WebmasterWorld Top Contributor of All Time 10+ Year Member

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?


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

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

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.


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


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

WebmasterWorld Administrator rogerd is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Looks like a possible path, thanks.


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.



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

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

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.

Featured Threads

Hot Threads This Week

Hot Threads This Month