6 replies [Last post]
rio_gio's picture
Offline
Joined: 08/23/2007
Juice: 90
Was this information Helpful?

Basically, my shop looks nice with only two columns, however I have more than two categories/sub categories and I still want to only have two columns for the stuff.

How do I do it?

Once I add a third item it doesn't display properly anymore, so I want ubercart to just go into another row with two columns.

You can see how the third column gets squished, how can I control this?

PreviewAttachmentSize
column.jpgcolumn.jpg43.93 KB
Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: How to change number of columns displayed in catalog?

I had thought about putting a setting for this before, but I keep running into a problem. The CSS rules for the catalog are set so that each column has the same width. If you change the number of columns, you have to change the width allotted to each (unless you're doing more customization than that anyway, but then the point is moot).

I can tell you which numbers to change so you can make it how you want to now, but I'd also like to know if I should make a setting for later versions. If I put it in, people might get confused when their columns look funny because they didn't know to change the CSS. If I don't, people might get annoyed that they have to keep changing the code every time they update Übercart. And I don't want to give anyone a reason not to update Übercart.

Anyway, here's what you need to do: in uc_catalog.module, search for "// could extract this number to a user-defined field". That line has the number of columns the categories are in, so change it to a 2. Next, look for td.category in uc_catalog.css. Change the width property to 50%. Alternatively, you can override that rule in a theme stylesheet so it won't be overridden when you update.

That's all it takes. Enjoy.

druru's picture
Offline
Brain Stormer
Joined: 08/08/2007
Juice: 228
Lyle, you could actually

Lyle,

you could actually automate this somewhat in php code. set up the catalog module so that it creates a class like "cat_col_#" where # is based on number of column settings so you get a class string like the following:

cat_col_2
cat_col_3
cat_col_4

etc

this class string (or col number) could then be passed into the the catalog theme (wherever that is) to add the column class to the catalog div (or table).

then, in your css you could simply hard code a number of td.category selectors with column classes ahead of time:

.cat_col_2 td.category { width: 50%;)
.cat_col_3 td.category { width: 33%;)
.cat_col_4 td.category { width: 25%;)
.cat_col_5 td.category { width: 20%;)

or something similar

most people are probaby not going to want to go over 5 cols or some limit.

in that case they have to go and change the css line themselves but the class will already be set, making it a lot easier to change and document (less support for you in the long run)

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Lyle, you could actually

Now that is a great idea. Thanks, druru.

druru's picture
Offline
Brain Stormer
Joined: 08/08/2007
Juice: 228
your welcome ... you can

your welcome Smiling...

you can actually use the same class / id technique for automating other similar css / theming situations in modules.

rio_gio's picture
Offline
Joined: 08/23/2007
Juice: 90
Re: your welcome ... you can

Thanks to both of you guys.

This is all very useful.

We've actually decided on not using the default catalog pages, rather creating custom pages for every category which will link into sub categories and finally to the product page. It's more work, but it's what the boss wanted, so I've gotta let her have her way.

mghatiya's picture
Offline
Joined: 11/23/2009
Juice: 24
Re: Re: your welcome ... you can

I see that this discussion has been realized today in form of function theme_uc_catalog_browse()

Thanks for that.

But I see that, that function is not called if Catalog is in a block.

Why so?