How to exclude certain category id from listing in latest ad?

ClassiBase classifieds script Forums General help How to exclude certain category id from listing in latest ad?

This topic contains 5 replies, has 2 voices, and was last updated by  Elite Tan 3 years, 1 month ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1108 Reply

    Elite Tan
    Participant

    dear Support, how to exclude certain category id from listing in latest ad?
    which line and code in ad.php do I need to modify to exclude the category id that I like to exclude from being listing in the latest ad, please advice and to hear from you soon, Thanks alot……………

    #1110 Reply

    Elite Tan
    Participant

    I mean example I’ve 10 category (Car, Bus, House, Job, etc), for category Bus I want to exclude from being listing in the latest ad, related ad, the category Bus id is say id “51”, so How do we exclude category Id “51” from being listing in the latest ad, related ad widget? Thanks alot and Please advice……….

    #1111 Reply

    ClassiBase
    Keymaster

    That is very difficult to do and not consistent functionality.

    We can tell you where to make updates but cannot provide exact code to do it.

    Latest and featured ads for widgets are populated in Widgets::widgetAds() model. Ads are selected from database in Ad::latestAds() and Ad::featuredByLocation() models.

    You will have to make changes to queries used in latest 2 functions.

    You probably need to add something like

    $where .= ' AND category_id!=51'; just before using it to retrieve data.

    We do not advise you making these changes because it may complicate functionality of script in future. You may face problem not seeing ads from bus category in any place.

    So do it on your own risk. And keep in mind that changes made to script will be lost on script update.

    #1112 Reply

    Elite Tan
    Participant

    I tried to add to below but not working can you please guide me is the categoery_id code correct or should be category or id or category_id, and the “where” need to add the dot “.”? please advice where to add below under the Ad.php to exclude category id 166, Thanks alot and to hear from you again……..
    ———
    public static function latestAds($num = 20, $location = null, $category = null)
    {

    $cache_key = ‘ad.latest.l’ . intval($location->id) . ‘.c’ . intval($category->id) . ‘.’ . intval($num);
    $ads = SimpleCache::get($cache_key);
    if($ads === false)
    {
    $whereA = array(‘ad.listed=?’);
    $whereB = array(1);

    Ad::buildLocationQuery($location, $whereA, $whereB);
    Ad::buildCategoryQuery($category, $whereA, $whereB);

    $where .= ‘ AND category_id!=166’;
    $where = str_replace(‘ad.’, ”, implode(‘ AND ‘, $whereA));

    $ads = Ad::findAllFrom(‘Ad’, $where . ‘ ORDER BY published_at DESC LIMIT ‘ . $num, $whereB);

    SimpleCache::set($cache_key, $ads);
    }
    return $ads;
    }

    #1114 Reply

    Elite Tan
    Participant

    I tried below also not working, any idea where exactly should be place, help……

    $ads = Ad::findAllFrom(‘Ad’, $where . ‘ ORDER BY published_at DESC LIMIT AND category_id!=166 ‘ . $num, $whereB);

    #1115 Reply

    Elite Tan
    Participant

    please ignore, is working now Support, thank you so much, just added below is correct, earlier i didn’t clear cache. after clearing cache and repost the ad now working already 166 has been excluded! hurray, thanks alot Support for the wonderful support 🙂

    $where .= ‘ AND category_id!=166′;
    $where = str_replace(‘ad.’, ”, implode(‘ AND ‘, $whereA));

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: How to exclude certain category id from listing in latest ad?
Your information: