OpenRealty Data Icon Tutorial
Posted on January 18, 2010
Filed Under General | 2 Comments
How to use images to represent data in OpenRealty
UPDATED! I tested this with WPRealty recently and the technique works fine.
Here is a quick little snippet that can be used in your OpenRealty template to display an image rather than a text value for various fields. I had a project recently that required the display of icons to represent data as opposed to text information. If for example there was a ski lodge or swimming available for the particular listing the client wanted to display an icon for that feature as he figured the YES/NO wasn’t very appealing aesthetically in his listing details. What I came up with was a simple snippet to display an image or alternate image depending on the value available in the database.
The demo icons to the left would for instance be displayed as blue in color if the value was a yes and a subdued color if there was a NULL or NO value. When a visitor scans the search results they could quickly spot visual representation of key things of importance such as heated swimming pool, ski lodge or exercise room and so on.
Here is the simple way of handling similar scenarios. First, you should determine where in your theme the images are to be displayed and make design provisions for that with sample mockup code. Images should always include ALT text so take that into account. Then, simply replace your mockup code with something similar to what I have outlined below.
Listing Details – Search Results – Template Code
Lets say that you want to display an icon for the virtual tour if the virtual tour actually has a value and the name of that field in your OpenRealty database is “VirtualTour” You simply place the following code in either the listing details template or search results template of your choice where you want the image to be displayed at. By doing so, if the VirtualTour field has a value it will display the image I called vtour.jpg and if no value I have it set to display a space. I could have it display an alternate image or any value per se.
Keep in mind that you do not have to repeat most of this snippet if the results are to appear in the same section of the template. When adding multiple instances you could add the require_once at the very top of your theme and call it globally.
<?php
$i=2;
require_once("functions.php");
$value = get_field_value('VirtualTour');
if($value){
//echo($value);
echo("<a href=".$value." title=\"Virtual Tour\"><img src=\"{baseurl}/template/default/images/vtour.jpg\" title=\"virtual tour\" /></a>");
}else{
echo(" ");
}
?>
OpenRealty functions.php File
In all OpenRealty themes I build I now include a functions.php file in the template directory much like we do in WordPress themes. In fact, WordPress is where I took the idea from because some sites need custom features that really do not necessitate the creation of an addon. So in the functions.php file I’ll include code necessary to handle various things such as our custom form kit or even a simple registration bridge or basic menu management features. The example code below is taken from one of the functions.php file for this particular project. Simply copy it and create your own functions.php file for inclusion into the theme folder.
Be sure to pay special attention to the top line for require_once as this should be set as your full root path. If you are not sure of the actual path you could create a path.php file and add the following to it <?php echo __FILE__; ?> By uploading and then navigating to the file you should get the full path printed in the browser.
<?php
// this is the functions.php file
// set the path below before adding to your template directory
require_once("/home/MYDOMAIN/public_html/include/common.php");
function get_field_value($field_name)
{
global $config;
$listingID=-1;
if(isset($_GET['listingID']) && $_GET['action']=='listingview')
{
$listingID=$_GET['listingID'];
$sql="select listingsdbelements_field_value from ".$config['table_prefix']."listingsdbelements where
listingsdbelements_field_name='".$field_name."' and listingsdb_id=".$listingID." LIMIT 1";
$select=mysql_query($sql);
$field_value=mysql_fetch_assoc($select);
if($field_value['listingsdbelements_field_value']){
return $field_value['listingsdbelements_field_value'];
}else{
return false;
}
}
}
?>
Although this tutorial is basic, you could do as I do and make the fields to query an array of field so you do not have to replicate the code over and over within your template. By doing so your results could look like the following for example;

Comments
Leave a Comment
If you would like to make a comment, please fill out the form below.
Shopping Cart
Recently
- WPRealty Features Short Code
- WordPress Approves ORPRESS
- I am taking a break from freelance
- OpenRealty Paid Support
- XML Feed Templates Download
- OpenRealty Data Icon Tutorial
- OpenRealty 2.5.8 Is Serious Competition
- OpenRealty Theme Options Addon
- WPRealty Sites Out Rank Competition
- Download WP Realty
Categories
- Adobe Dreamweaver
- Announcements
- Code Snippets
- Design
- General
- Joomla CMS
- Open Realty
- Open Realty Tips
- Portfolio
- Products
- Products in Review
- Professionals In Review
- Real Estate News
- Real Estate Websites
- Technical Resources
- Template Design Kit
- Week in Review
- WordPress Wisdom
Archives
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007

Works perfect, thanks for the great tutorial
Excellent solution, IT Works! Beautiful job man I love the wisdom you have with OpenRealty.