PDA

View Full Version : [Auto Classified] Create page/content box to display new vehicles in specific make



Son Vu
July 25, 2016, 04:41 AM
I want to create a page or content box to display new listings belong to specific make. For example, all new Ford vehicles. Who knows how to do it, please help me out. Thanks so much!

Viktor
July 25, 2016, 06:58 AM
Hello Son Vu,

I think we can create it like a small customization. Would you please create a ticket with your request.

Catalin B
July 25, 2016, 10:44 AM
Hello Son Vu,

I think we can create it like a small customization. Would you please create a ticket with your request.


Please post it here too, I want to know it too, and I hope more are looking for this mod ;)

Thanks

Viktor
July 25, 2016, 12:20 PM
Hello All,

Who want this customization want to try my code:

go to ftp://includes>>classes>>rlListings.class.php

and add new method:



/**
* get listings by category key
*
* @param string $category_id - category Key
* @param string $order - field name for order
* @param string $order_type - order type
* @param int $limit - listing number per request
*
* @return array - listings information
**/
function getListingsCustom($category_key = false, $order = false, $order_type = 'ASC', $limit = 10)
{
global $sql, $config, $rlListingTypes, $rlValid;

if($category_key) {
$rlValid->sql($category_key);

$category = $this -> fetch(array('ID', 'Type'), array('Key' => $category_key, 'Status' => 'active'), null, 1, 'categories', 'row');

$category_id = $category['ID'];
$listing_type = $category['Type'];
} else {
return;
}


$hook = '';

$sql = "SELECT {hook} ";

$sql .= "`T1`.*, `T3`.`Path` AS `Path`, `T3`.`Key` AS `Key`, `T3`.`Type` AS `Listing_type`, `T3`.`Parent_keys`, ";

$GLOBALS['rlHook'] -> load('listingsModifyField');

$sql .= "IF(`T1`.`Featured_date`, '1', '0') `Featured` ";
$sql .= "FROM `" . RL_DBPREFIX . "listings` AS `T1` ";
$sql .= "LEFT JOIN `" . RL_DBPREFIX . "categories` AS `T3` ON `T1`.`Category_ID` = `T3`.`ID` ";

if ($GLOBALS['conversion_rates'][ $sorting[$order]['Condition'] ]) {
foreach ($sorting as $key => $fVal) {
if ($GLOBALS['conversion_rates'][$fVal['Condition']] && $fVal['Condition']) {
$sql .= "LEFT JOIN `" . RL_DBPREFIX . "data_formats` AS `TDF_{$fVal['Condition']}` ON `TDF_{$fVal['Condition']}`.`Key` = SUBSTRING_INDEX(`T1`.`{$fVal['Key']}`, '|', -1) ";
}
}
}

$GLOBALS['rlHook'] -> load('listingsModifyJoin');

$sql .= "WHERE `T1`.`Status` = 'active' ";

if ($category_id > 0) {
$sql .= "AND (`T1`.`Category_ID` = '{$category_id}' OR (FIND_IN_SET('{$category_id}', `T1`.`Crossed`) > 0) ";

if ($config['lisitng_get_children']) {
$sql .= "OR FIND_IN_SET('{$category_id}', `T3`.`Parent_IDs`) > 0 ";
}

$sql .= ") ";

$hook = "IF (FIND_IN_SET('{$category_id}', `T1`.`Crossed`) > 0, 1, 0) AS `Crossed_listing`, ";
} else {
$sql .= "AND `T3`.`Type` = '{$listing_type}' ";
}

$GLOBALS['rlHook'] -> load('listingsModifyWhere');
$GLOBALS['rlHook'] -> load('listingsModifyGroup');
$rlValid->sql($order);
$rlValid->sql($order_type);

$sql .= "ORDER BY ";
if ( $order )
{
$sql .= " `{$order}` ". strtoupper($order_type) . " ";
} else {
$sql .= " `T1`.`Date` DESC ";
}

$sql .= "LIMIT {$limit} ";

/* replace hook */
$sql = str_replace('{hook}', $hook, $sql);

$listings = $this -> getAll($sql);
$listings = $GLOBALS['rlLang'] -> replaceLangKeys( $listings, 'categories', 'name' );

if ( empty($listings) )
{
return false;
}

if ( !$config['cache'] )
{
$alternative_category_id = $listing_type ? $rlListingTypes->types[$listing_type]['Cat_general_cat'] : $category_id;
$fields = $this -> getFormFields($alternative_category_id, 'featured_forms', $listings[0]['Listing_type']);
}

foreach ( $listings as $key => $value )
{
$GLOBALS['rlCommon'] -> listings[ $value['ID'] ] = $value;

/* populate fields */
if ($config['cache'] || $category_id == 0) {
$fields = $this -> getFormFields( $value['Category_ID'], 'short_forms', $value['Listing_type'] );
}

foreach ( $fields as $fKey => $fValue ) {
$fields[$fKey]['value'] = $GLOBALS['rlCommon'] -> adaptValue( $fValue, $value[$fKey], 'listing', $value['ID'], true, false, false, false, $value['Account_ID'] );
}

$listings[$key]['fields'] = $fields;

$listings[$key]['listing_title'] = $this -> getListingTitle( $value['Category_ID'], $value, $value['Listing_type'] );
$listings[$key]['url'] = $this -> url('listing', $listings[$key]);
}
return $listings;
}


then go to ftp://templates>>tpl>>your_template>>tpl>>blocks and create new file with name: custom_listings.tpl

and add code in:



{php}
global $page_info;

$block = $this -> get_template_vars('block');
$side_bar_exists = $this -> get_template_vars('side_bar_exists');
$class = 'col-md-3 col-sm-4';

if ($page_info['Key'] == 'home') {
if (in_array($block['Side'], array('middle_left', 'middle_right'))) {
$class = 'col-md-6 col-sm-4';
}
} else {
if (in_array($block['Side'], array('middle', 'bottom', 'top'))) {
$class = $side_bar_exists ? 'col-sm-4' : 'col-md-3 col-sm-4';
} elseif (in_array($block['Side'], array('middle_left', 'middle_right'))) {
$class = 'col-md-12 col-sm-4';
}
}

$this -> assign('box_item_class', $class);
{/php}
{assign var='listings' value=$custom_listings.$custom_cat_key}
{if !empty($listings)}
<ul class="row featured clearfix with-pictures">{strip}
{foreach from=$listings item='featured_listing' key='key' name='listingsF'}
{assign var='type' value=$featured_listing.Listing_type}
<li {if $featured_listing.ID}id="fli_{$featured_listing.ID}"{/if} class="{$box_item_class}{if !$featured_listing.Main_photo} no-picture{/if}">
{if $listing_types.$type.Photo}
{if $featured_listing.Main_photo}
{assign var='hrsrc' value=$smarty.const.RL_FILES_URL|cat:$featured_lis ting.Main_photo|regex_replace:'/\.([^\/]+)$/':'_large.$1'}
{assign var='hrsrc_path' value=$smarty.const.RL_FILES|cat:$featured_listing .Main_photo|regex_replace:'/\.([^\/]+)$/':'_large.$1'}
{/if}

{if $listing_types.$type.Page}<a title="{$featured_listing.listing_title}" {if $config.featured_new_window}target="_blank"{/if} href="{$featured_listing.url}">{/if}
<img alt="{$featured_listing.listing_title}" src="{$rlTplBase}img/blank_10x7.gif" {if $featured_listing.Main_photo}data-1x="{$smarty.const.RL_FILES_URL}{$featured_listing.Mai n_photo}" data-2x="{if $hrsrc_path|is_file}{$hrsrc}{else}{$smarty.const.R L_FILES_URL}{$featured_listing.Main_photo}{/if}"{/if} {if !$demo_gallery}{if $featured_listing.Main_photo}style="background-image: url({if !$featured_listing.custom}{$smarty.const.RL_FILES_ URL}{/if}{$featured_listing.Main_photo});"{/if} {if $hrsrc_path|is_file}accesskey="{$hrsrc}"{/if}{/if} />
{if $listing_types.$type.Page}</a>{/if}
{/if}

<ul {if !$featured_listing.fields.price.value}class="no-price"{/if}>
{assign var='first_field' value=true}
{foreach from=$featured_listing.fields item='item' key='field' name='fieldsF'}
{if !empty($item.value)}
<li title="{$item.value|strip_tags}" class="{if $item.Key == 'price'}price_tag two-inline{/if}" id="flf_{$featured_listing.ID}_{$item.Key}">
{if $first_field && $item.Key != 'price'}
{if $listing_types.$type.Page}<a {if $config.featured_new_window}target="_blank"{/if} href="{$featured_listing.url}">{/if}
{$item.value}
{if $listing_types.$type.Page}</a>{/if}
{else}
{rlHook name='tplFeaturedItemPrice'}
<div>{$item.value}</div>
{/if}
</li>
{if $item.Key != 'price'}{assign var='first_field' value=false}{/if}
{/if}
{/foreach}
</ul>
</li>
{/foreach}
{/strip}</ul>
{/if}


and then create new box in Admin Panel >> Content Boxes with type 'PHP' and insert code:


if(false === is_object($rlListings)){
$GLOBALS['reefless']-> loadClass('Listings');
}

$custom_listings['apartment_complex'] = $GLOBALS['rlListings'] -> getListingsCustom('apartment_complex', 'Date', 'DESC', 10);

$GLOBALS['rlSmarty'] -> assign_by_ref( "custom_listings", $custom_listings );
$custom_cat_key = "apartment_complex";
$GLOBALS['rlSmarty'] -> assign_by_ref( "custom_cat_key", $custom_cat_key );
$GLOBALS['rlSmarty'] -> display( "blocks" . RL_DS . "custom_listings.tpl" );

where 'apartment_complex' it is category key (please be careful because you should set category key in 2 places in the code)
Date - field for ordering
DESC - type for ordering
10 - number listings

Catalin B
July 26, 2016, 08:42 PM
Thank you very much Viktor

Son Vu
July 29, 2016, 09:21 AM
I love you, Viktor. I'll test it out tonight :)