Widget Content Bottom Per Category

ClassiBase classifieds script Forums General help Widget Content Bottom Per Category

This topic contains 6 replies, has 3 voices, and was last updated by  Clifford Enoc 2 years ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #2614 Reply

    Can we have PHP code on content bottom for conditional statement on Ad page show according to category?

    example:

    Cars and their children subcat
    the widget content bottom will show under this category so we can add multiple content bottom (or top) per category?

    Thanks!

    and great script btw…

    #2619 Reply

    infoactivo
    Participant

    This code allows you to get category name, description and url.
    Insert the code as text, in php format, at the inner bottom of your widgets. Hide to all except to category page.
    I’m not able to get the category id so, if you get a way to have it, please share – I’ll appreciate every improvement to code you can share.

    <?php
      $catgName = '';
      $catgDescription = '';
      $selected_category = self::$_vars['selected_category'];
      if($selected_category)
      {
        $y_url = Location::url($l, $selected_category);
        $catgurl = str_replace(BASE_URL, "", $y_url);
        $catgName = View::escape(Category::getName($selected_category));
        $catgDescription = View::escape(Category::getDescription($selected_category)); 
        echo 'Name: '. $catgName .', Description: '. $catgDescription .', URL: '. $catgurl;
      }  
    ?>
    #2622 Reply

    ClassiBase
    Keymaster

    Above example is good in addition here are some adjustments to it. To get category absolute url with current location then you can use like this $y_url = Location::url(self::$_vars['selected_location'], $selected_category);

    Also if you want to check as in your request if there is ‘Cars’ category in parent categories then use this code. For example you know cars category ID is 15. You can check with name but if you have multilingual site then name is not good for checking:

    if($selected_category->id==15)
    {
      // this cars category with id 15 do what you want with it here
    }
    else
    {
      // check if subcategory of cars
      $parent_cats = Category::getParents($selected_category);
      foreach($parent_cats as $parent_cat)
      {
        if($parent_cat->id==15)
        {
          // this is subcategory of cars with id 15
        }
      }
    }

    To get id of location, category, ad you can always use ->id property of object, for example $ad->id.

    #2625 Reply

    this doesn’t work

    if($selected_category->id==15)
    {
      // this cars category with id 15 do what you want with it here
    }
    else
    {
      // check if subcategory of cars
      $parent_cats = Category::getParents($selected_category);
      foreach($parent_cats as $parent_cat)
      {
        if($parent_cat->id==15)
        {
          // this is subcategory of cars with id 15
        }
      }
    }
    #2628 Reply

    infoactivo
    Participant

    It does work for me. Please verify you enter the whole code and be sure to enter the <?php ?> part.
    I use this for testing on category id = 1, transport in my case:

    <?php
    
      $selected_category = self::$_vars['selected_category'];
    if($selected_category->id==1)
    {
        // this Transport category with id 1 do what you want with it here
        $catgID = $selected_category->id;
        $y_url = Location::url(self::$_vars['selected_location'], $selected_category);
        $curl = $y_url; // str_replace(BASE_URL, "", $y_url);
        $catgName = View::escape(Category::getName($selected_category));
        $catgDescription = View::escape(Category::getDescription($selected_category)); 
        echo 'ID: '. $catgID .', Name: '. $catgName .', Description: '. $catgDescription .', URL: '. $curl;
    }
    else
    {
      // check if subcategory of Transport
      $parent_cats = Category::getParents($selected_category);
      foreach($parent_cats as $parent_cat)
      {
        if($parent_cat->id==1)
        {
          // this is subcategory of Transport with id 1
        $catgID = $selected_category->id;
        $y_url = Location::url(self::$_vars['selected_location'], $selected_category);
        $curl = $y_url; // str_replace(BASE_URL, "", $y_url);
        $catgName = View::escape(Category::getName($selected_category));
        $catgDescription = View::escape(Category::getDescription($selected_category)); 
        echo 'ID: '. $catgID .', Name: '. $catgName .', Description: '. $catgDescription .', URL: '. $curl;      
        }
      }
    } 
    
    ?>
    #2631 Reply

    infoactivo: yes that code works for me now. The previous code was entered correct with proper php code <?php ?> but does not work. Your code work. I don’t know why.

    #2634 Reply

    another thing.

    How about multiple categories?
    $selected_category->id==1

    how to code for example exclude cat id 1 and show other categories:
    $selected_category->id!==1

    or multiple categories:
    $selected_category->id=array(2,3,4)

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: Widget Content Bottom Per Category
Your information: