OpenRealty Data Icon Tutorial

Posted on January 18, 2010
Filed Under General, Real Estate Scripts | 2 Comments

How to use images to represent data in Open-Realty®

UPDATED! I tested this with WPRealty recently and the technique works fine.

Here is a quick little snippet that can be used in your Open-Realty® 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.

Search Results 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 Open-Realty® 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("&nbsp;");
}
?>

Open-Realty® functions.php File

In all Open-Realty® 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;
Search Results

Comments

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

2 Comments so far
  1. Dubai Realtor January 20, 2010 3:29 am

    Works perfect, thanks for the great tutorial

  2. DJC January 20, 2010 9:11 am

    Excellent solution, IT Works! Beautiful job man I love the wisdom you have with OpenRealty.


TEMP CODE: GDHXCDX17249629