Advertisement:

Author Topic: [Tutorial] Showing different images per main category instead of no_photo.gif  (Read 15287 times)

navjottomer

  • Tutor
  • Sr. Member
  • *
  • Posts: 378
  • I am here
Have you wondered how to show different images in latest ad list and in search list when no photo is uploaded for that item?
Here is a short tutorial for showing different images according to item parent category.
1. First of all add this code to your theme functions.php

Code: [Select]
function osc_item_parent_category_id() {
        if ( !View::newInstance()->_exists('item_category') ) {
            View::newInstance()->_exportVariableToView('item_category', Category::newInstance()->findByPrimaryKey( osc_item_category_id() ) );
        }
        $category = View::newInstance()->_get('item_category') ;
        return (int) osc_field($category, "fk_i_parent_id", "") ;
    }

This function will allow you to fetch item parent category id.


2. Now put your png images (You can choose images of any type but for that make changes in code too ) in your theme image folder and name them according to your main category.
Like if your main categories id are 2,8,30,45  than rename images like  2.png , 8.png , 30.png , 45.png


3. Now make some changes to your main.php and searchlist.php

replace this line

Code: [Select]
<img src="<?php echo osc_current_web_theme_url('images/no_photo.gif') ; ?>" alt="" title="" />
whit this one
Code: [Select]
<img src="<?php echo osc_current_web_theme_url('images/') . osc_item_parent_category_id() .'.png' ?>" alt="No image available" />
(If you are running any OSX version than Text Wrangler is a good tool to do these things).

All done. TADA!!!  8)


I have tested this with Osclass3.0 only although it may work in other versions too.
« Last Edit: October 12, 2012, 10:22:15 pm by navjottomer »

trains58554

  • Osclass contributor
  • Hero Member
  • *****
  • Posts: 3642
  • osCanyon, the class of Osclass
Hi navjottomer,

Very nice tutorial.

Thanks

Jay

texthiller

  • Full Member
  • ***
  • Posts: 207
Good! thanks you!

navjottomer

  • Tutor
  • Sr. Member
  • *
  • Posts: 378
  • I am here
Please change previous function to this.
Code: [Select]
function osc_item_parent_category_id() {
        if ( !View::newInstance()->_exists('item_category') ) {
            View::newInstance()->_exportVariableToView('item_category', Category::newInstance()->findByPrimaryKey( osc_item_category_id() ) );
        }
        $category = View::newInstance()->_get('item_category') ;
        return (int) osc_field($category, "fk_i_parent_id", "") ;
    }

Legion

  • Hero Member
  • *****
  • Posts: 622
  • I am founder of top20remedies.com buyeradvise.com
i tried but photos not visible on my site

www.offersvalley.com

navjottomer

  • Tutor
  • Sr. Member
  • *
  • Posts: 378
  • I am here
i tried but photos not visible on my site

www.offersvalley.com

Did you get any error or something?

Legion

  • Hero Member
  • *****
  • Posts: 622
  • I am founder of top20remedies.com buyeradvise.com
No error but photos are not looking  :-[

navjottomer

  • Tutor
  • Sr. Member
  • *
  • Posts: 378
  • I am here
did you putted my code at the right place? I think you have placed my code without following my proper instructions posted earlier. Can you share your main.php and functions.php so i can check it.

Legion

  • Hero Member
  • *****
  • Posts: 622
  • I am founder of top20remedies.com buyeradvise.com
no dude

navjottomer

  • Tutor
  • Sr. Member
  • *
  • Posts: 378
  • I am here
Did you copy/pasted my code in your files? If yes, where?  :o

Legion

  • Hero Member
  • *****
  • Posts: 622
  • I am founder of top20remedies.com buyeradvise.com
there was a prob with amazon s3 plugin


« Last Edit: October 13, 2012, 05:23:01 pm by Legion »

diklik

  • Newbie
  • *
  • Posts: 2
very helpful tricks.
and how to show icon for each categories like tuffclassified?

navjottomer

  • Tutor
  • Sr. Member
  • *
  • Posts: 378
  • I am here
very helpful tricks.
and how to show icon for each categories like tuffclassified?
It's been already answered by someone else in this forum.

mrreference

  • Jr. Member
  • **
  • Posts: 74
Hi, can you tell me where I have to place the function code to exactly in the functions.php please.  I have moved it around and I still cannot get the images to display.  Also, what is the quickest way to find out what my categories are called so i can save my images as the correct filenames?

I presume this works on the latest version 3.1?

navjottomer

  • Tutor
  • Sr. Member
  • *
  • Posts: 378
  • I am here
Hi, can you tell me where I have to place the function code to exactly in the functions.php please.  I have moved it around and I still cannot get the images to display.  Also, what is the quickest way to find out what my categories are called so i can save my images as the correct filenames?

I presume this works on the latest version 3.1?
You can add this in your theme function file anywhere. Use phpmyadmin or view source of your homepage.