Site icon Osclass Documentation & Knowledge Base

Display only certain type of listings

In OSClass 3.0 we introduced the function osc_query_item($params) where $params could be a string or an array.

Example of usage

You should call osc_query_item($params) function and later loop through the items with the “custom_items” helpers as usual

Only one keyword:

osc_query_item("keyword=value1,value2,value3,...");

Multiple keywords:

osc_query_item(array(
    "keyword1" => "value1,value2",
    "keyword2" => "value3,value4"
));

Real live examples

Only one keyword:

<?php osc_query_item("region_name=Madrid");
if( osc_count_custom_items() == 0) { ?>
    <p class="empty"><?php _e('No Listings', 'modern') ; ?></p>
<?php } else { ?>
    <table border="0" cellspacing="0">
         <tbody>
            <?php $class = "even"; ?>
            <?php while ( osc_has_custom_items() ) { ?>
             <tr class="<?php echo $class. (osc_item_is_premium()?" premium":"") ; ?>">
                    <?php if( osc_images_enabled_at_items() ) { ?>
                     <td class="photo">
                        <?php if( osc_count_item_resources() ) { ?>
                            <a href="<?php echo osc_item_url() ; ?>">
                                <img src="<?php echo osc_resource_thumbnail_url() ; ?>" width="75" height="56" title="<?php echo osc_item_title(); ?>" alt="<?php echo osc_item_title(); ?>" />
                            </a>
                        <?php } else { ?>
                            <img src="<?php echo osc_current_web_theme_url('images/no_photo.gif') ; ?>" alt="" title=""/>
                        <?php } ?>
                     </td>
                    <?php } ?>
                     <td class="text">
                         <h3><a href="<?php echo osc_item_url() ; ?>"><?php echo osc_item_title() ; ?></a></h3>
                         <p><strong><?php if( osc_price_enabled_at_items() ) { echo osc_item_formated_price() ; ?> - <?php } echo osc_item_city(); ?> (<?php echo osc_item_region();?>) - <?php echo osc_format_date(osc_item_pub_date()); ?></strong></p>
                         <p><?php echo osc_highlight( strip_tags( osc_item_description() ) ) ; ?></p>
                     </td>                                       
                 </tr>
                <?php $class = ($class == 'even') ? 'odd' : 'even' ; ?>
            <?php } ?>
        </tbody>
    </table>
<?php }; ?>

Multiple keywords:

<?php osc_query_item(array(
    "category_name" => "cars,houses",
    "city_name" => "Madrid"
));
if( osc_count_custom_items() == 0) { ?>
    <p class="empty"><?php _e('No Listings', 'modern') ; ?></p>
<?php } else { ?>
    <table border="0" cellspacing="0">
         <tbody>
            <?php $class = "even"; ?>
            <?php while ( osc_has_custom_items() ) { ?>
             <tr class="<?php echo $class. (osc_item_is_premium()?" premium":"") ; ?>">
                    <?php if( osc_images_enabled_at_items() ) { ?>
                     <td class="photo">
                        <?php if( osc_count_item_resources() ) { ?>
                            <a href="<?php echo osc_item_url() ; ?>">
                                <img src="<?php echo osc_resource_thumbnail_url() ; ?>" width="75" height="56" title="<?php echo osc_item_title(); ?>" alt="<?php echo osc_item_title(); ?>" />
                            </a>
                        <?php } else { ?>
                            <img src="<?php echo osc_current_web_theme_url('images/no_photo.gif') ; ?>" alt="" title=""/>
                        <?php } ?>
                     </td>
                    <?php } ?>
                     <td class="text">
                         <h3><a href="<?php echo osc_item_url() ; ?>"><?php echo osc_item_title() ; ?></a></h3>
                         <p><strong><?php if( osc_price_enabled_at_items() ) { echo osc_item_formated_price() ; ?> - <?php } echo osc_item_city(); ?> (<?php echo osc_item_region();?>) - <?php echo osc_format_date(osc_item_pub_date()); ?></strong></p>
                         <p><?php echo osc_highlight( strip_tags( osc_item_description() ) ) ; ?></p>
                     </td>                                       
                 </tr>
                <?php $class = ($class == 'even') ? 'odd' : 'even' ; ?>
            <?php } ?>
        </tbody>
    </table>
<?php }; ?>

List of available keywords