Display only a certain type of items

Display items based on category, location or another type of filters with osc_query_item() function available in Osclass.

Filters available for this function:

  • id = you can display only a specific item by adding the id of that item;
  • pattern = you can add a search word and filter the items based on that search word;
  • author = display the items of a single user by passing the id of that user;
  • category or category_name =  add a category by id or by name to display the items of  a single category;
  • country or country_name = filter by country id or country name;
  • region or region_name = filter by region id or name;
  • city or city_name = filter by city id or name;
  • city_area or city_area_name = filter by city area;
  • result_per_page = limit the number of results displayed;
  • premium = display only premium ads;
  • page = you can use pagination for this type of items(the current page);
  • limit = limit the results of the search;

 

Usage examples:

​
​<?php
osc_query_item(array(
    "category" => "1"
));
?>
<?php if (osc_count_custom_items() > 0) { ?>
    <div class="latest_ads">
        <?php while (osc_has_custom_items()) { ?>
            <?php $size = explode('x', osc_thumbnail_dimensions()); ?>
            <li class="<?php osc_run_hook("highlight_class"); ?>listing-card <?php if (osc_item_is_premium()) { ?><?php echo ' premium'; ?> <?php } ?>">
            <?php if (osc_images_enabled_at_items()) { ?>
                <?php if (osc_count_item_resources()) { ?>
                    <a class="listing-thumb" href="<?php echo osc_item_url(); ?>" title="<?php echo osc_esc_html(osc_item_title()); ?>"><img src="<?php echo osc_resource_thumbnail_url(); ?>" title="" alt="<?php echo osc_esc_html(osc_item_title()); ?>" width="<?php echo $size[0]; ?>" height="<?php echo $size[1]; ?>"></a>
                <?php } else { ?>
                    <a class="listing-thumb" href="<?php echo osc_item_url(); ?>" title="<?php echo osc_esc_html(osc_item_title()); ?>"><img src="<?php echo osc_current_web_theme_url('images/no_photo.gif'); ?>" title="" alt="<?php echo osc_esc_html(osc_item_title()); ?>" width="<?php echo $size[0]; ?>" height="<?php echo $size[1]; ?>"></a>
                <?php } ?>
            <?php } ?>
            <div class="listing-detail">
                <div class="listing-cell">
                    <div class="listing-data">
                        <div class="listing-basicinfo">
                            <a href="<?php echo osc_item_url(); ?>" class="title" title="<?php echo osc_esc_html(osc_item_title()); ?>"><?php echo osc_item_title(); ?></a>
                            <div class="listing-attributes">
                                <span class="category"><?php echo osc_item_category(); ?></span> -
                                <span class="location"><?php echo osc_item_city(); ?> <?php if (osc_item_region() != '') { ?> (<?php echo osc_item_region(); ?>)<?php } ?></span> <span class="g-hide">-</span> <?php echo osc_format_date(osc_item_pub_date()); ?>
                                <?php if (osc_price_enabled_at_items()) { ?><span class="currency-value"><?php echo osc_format_price(osc_item_price()); ?></span><?php } ?>
                            </div>
                            <p><?php echo osc_highlight(osc_item_description(), 250); ?></p>
                        </div>
                    </div>
                </div>
            </div>
        </li>
    <?php } ?>
</div>
<?php } ?>

The above example is for bender theme and you need to match your theme structure to have a proper display of the items. In the above code, we only filter by category but you can include other filters available in this function.

 

Category and user:

​<?php
osc_query_item(array(
    "category" => "1",
    "author" => "12" //user id
));
?>
<?php if (osc_count_custom_items() > 0) { ?>
    <div class="latest_ads">
        <?php while (osc_has_custom_items()) { ?>
        .........
        <?php } ?>
    </div>
<?php } ?>

Only region:

​<?php
osc_query_item(array(
    "region_name" => "alabama"
));
?>
<?php if (osc_count_custom_items() > 0) { ?>
    <div class="latest_ads">
        <?php while (osc_has_custom_items()) { ?>
        .........
        <?php } ?>
    </div>
<?php } ?>

You can combine any filter to display items, if any item will match the filters you will have results.

Subscribe
X

Subscribe!

Subscribe to get the latest listings, updates and special offers delivered directly in your inbox.