Building an ExpressionEngine Site - Chapter 10

Adding Category Images and Custom Category Fields.

In this chapter of the Building an ExpressionEngine Site we’ll build on the Products index page that we started in Chapter 9.

Yeah - I know.  It’s not exactly what I said we’d do at the end of Chapter 9—but I continue to see questions come up around the use of the custom category fields that became available in EE 1.6, and we’re at the perfect place to work a couple of those in.

Specifying Category Images
First let’s start with adding some thumbnail images to our categories for a bit of a visual cue about what wer’e (supposedly) selling.  We need to find the images, size them, get them to the server, and then edit our category setup.

  • The first step is to choose your images and resize them appropriately.  I’ve put mine at 150px wide by 112 tall
  • Load them up to the server.  Note that the current EE interface does not provide a File Upload feature for category images (now is the time you can add your vote to the feature request for this), so you’ll need to FTP them up instead.  I’ve created a specific directory under the default EE images directory for mine
  • OK - now we need to specify the image for each category.  Back in the EE control panel, navigate to Admin > Weblog Administration > Category Management, choose your category, and click the “Add/Edit Categories” link by it
  • Choose the category to edit and click the Edit link for it
  • The Category Image URL field is where we need to put the path and filename to the category image.  This is another place that I like to use the { site_url } variable so that the full path is specified.  An example of one of my paths is “{ site_url }images/bees/category_accessories_150.jpg”.  (Note - remove the spaces in the site url variable)
  • Click Update to save your changes
  • Repeat for each category you’ve created. A timesaver here is to name your images in a similar fashion, and once you’ve entered the first path and filename just copy/paste it for each category and change the filename

Displaying Category Images
The next natural step would be to go back to the Products template and modify it to pull our new category images.  However —we are also going to add some custom category fields which will also require changing the Products template to display.  Rather than give you two versions of the Products template I’ll give you the final version below and point out what’s been added for both the images and custom fields.

Category Custom Fields
With EE 1.6 came the ability to add custom fields at the category level - and I’ve seen a lot of confusion over how or why you would use these in the EE forums.  Since we are working still at the category level let’s throw in a couple just to show what you might do with them on this site.

If we imagine that our site is for a distributor of automotive accessories (as the Product Categories would indicate), it’s likely that each category would have it’s own Line Manager, who would have their own phone number to call for questions regarding the product line. 

So let’s add custom category fields for a name and a phone number to asscociate that data with our product categories:

  • In the EE Control Panel navigate back to Admin > Weblog Administration > Category Management
  • Find your Product Category group and click the “Manage Custom Fields” link on it’s row
  • Click the “Create a New Custom Field” button
  • Add your fields.  I’m creating a field called “category_manager” and “manager_phone”, both Text Input with no default text formatting applied
  • Edit your Categories.  Now that you have additional fields, you’ll need to go back and enter data into them for each category

The Updated Products Template
I’ve updated the Products Index template—you can see the rendered page here: Chapter 10 Products.

Here is the text version of the template: chapter_10_products.txt.

Let’s go through the changes, which are all within the weblog:categories tag:

  • The H2 class and title are the same as before
  • In the first paragraph, I’ve added an img tag that uses the category_image variable as it’s source, and the category_name as the alt text and title.  I’ve also set the image height and width here as they are all the same
  • Note that I applied a class="category_image" to the image, and created a selector in the stylesheet to add some margin to the bottom of each image.
  • Under the image code I’m now bringing in the custom category fields for category_manager and manager_phone
  • I put the category_description in it’s own paragraph
  • I had to add a div to clear the left float - otherwise the entries past the first category will stack up rather than aligning correctly to the left.  You may not need this depending on the relative lengths of your descriptions and size of your images

OK - I think we’re now setup well for the next chapter which will be creating the category index views showing the individual products in each category.

On to Chapter 11.
Back to Chapter 9.

Learn ExpressionEngine® Fast

Visit Train-ee.com for the latest in ExpressionEngine training designed with one goal in mind - to get you up to speed on ExpressionEngine® as quickly as possible.

The latest Train-ee Products:

The latest from the Train-ee blog:

Comments

1

October 12, 2007

Comprehensive and timely as ever…

So it looks like you are building the site in the order that the top tab navigation appears:
* Home - done
* About - done
* Products - in progress
* Services - still to go
* Weblog - coming soon
* Contact - stay tuned.
Does that sound about right or are some of those pages finished?
I never realized you documentation of the progress would be so complete and quite so many chapters.

Looks like you’re taking another weekend off then smile Enjoy!
I’m a little miffed you weren’t mentioned as a Nobel Prize candidate:
http://nobelprize.org/
We really really appreciate your taking the time complete this tremendously insightful series.

2
(Author)
October 12, 2007

Hey Ty - thanks for the comments.

What you see on the site is what’s finished.  There is no overall plan or pre-work, I’m just chipping away at it once a week in bite-sizes that seem appropriate at the time.

Nobel Prize - eh, if Al Gore can win it the bar is much lower than I previously thought...wink

3

October 12, 2007

Thanks yet again Mike...I’m tracking with ya!!! So helpful!

4

October 23, 2007

After a slow start, I’ve worked through the end of Chap. 10- What a great tutorial - I’m beginning to get my arms around EE.

Thanks, Michael.

5

November 21, 2007

Hi All,
Has anybody seen the Upload File extension by Mark Huot?
http://docs.markhuot.com/ee/extensions/file
New one on you then Mike, judging by the feature request linkover to EE in this chapter?
Love to hear any feedback on this file extension.

6
(Author)
November 22, 2007

My feature request is for a native file upload ability in the category interface of EE for category images.

Marc’s extension - near as I can tell anyway - creates a different process for uploading files in weblog posts - not at the category level.

7

November 22, 2007

Hi again, just installed a copy of EE 1.6.1 and noticed under:
Publish › New Entry › Default Site Weblog > Options
that there is an upload file button there beneath the preview and submit buttons on the right.
Clicking on upload file and there is a drop-down for Main upload directory is the only thing there, is there anyway to add locations to this dropdown menu?
Is this anything new? Just thought I would check, where better to ask?
A new feature called Live Look also had me curious, I’ld like to see screenshots of that, not quite sure where that is, or how it works it mentions something about a live look template.

8
(Author)
November 22, 2007

Yes - that’s the file upload for a weblog post - it’s been there since the get-go in EE (just finally got a text label in 1.6).

You can add file upload locations under weblog preferences > global weblog preferences.

I just played with Live Look - it lets you assign a template to a weblog to give sort of a “in context” view of the entry.  I haven’t played with it much but I was disappointed that I only got the link to it after publishing - I was hoping it’d be right next to quick save/preview as workflow-wise I’d want to see it before a final entry publish.

9
Rick S.
December 24, 2007

Been following the series but now I am getting a little off-base. My page for this chapter looks OK except there is no styling applied to the information. It is all just bundled into one paragraph. Do I apply the CSS properties in the template?

10
(Author)
December 26, 2007
Do I apply the CSS properties in the template?

Not sure what you mean here - you define styles in the CSS template then apply them in the other templates.

Have you run the page through the W3C HTML and CSS validator?  That’d be my first step.

Oh - also make sure you re-grab the CSS for the tutorial.

11
(Author)
January 15, 2008

FYI:  The Building an ExpressionEngine Site series is now available for purchase as an eBook on the newly-launched Train-ee.com.

12

February 10, 2008

Hi,

I can’t seem to get my images to come in. I am using the hosted trial and uploaded my images through the “File Upload” feature on the publish page. As I understand it, the default folder is called “uploads”.

BELOW IS MY LEFT SIDE DIV CODE:

<div id="left_side">
{exp:weblog:categories weblog="products" style="linear" show_empty="yes"}
<h2 class="underline">{category_name}</h2>

{category_image}

Line Manager:{category_manager}

Phone:{manager_phone}

{category_description}  View Products>>

<div style="clear:left"></div>

{/exp:weblog:categories}

</div><!--close left side-->

BELOW IS MY SOURCE CODE AFTER RENDERING:

<h2 class="underline">Accessories</h2>

http://demo.expressionengine.com/WGG4L02LMS/images/uploads/tableAccent.jpg

Line Manager:Mark Herndon

Phone:954-985-878

This is the description for the Accessories category.  View Products>>

<div style="clear:left"></div>

THE OTHER IMAGE SOURCE CODE IN THE TEMPLATE USES THE SAME PATHWAY AND THE IMAGES COME OUT FINE:

http://demo.expressionengine.com/WGG4L02LMS/images/uploads/img2.gif

thanks again for your help

13

February 10, 2008

I was able to determine what my problem was. I was modifying the name of the image in the browse field when I uploaded it from the File Upload feature on the publish page. For some reason I thought that had worked for me before. When I re-uploaded the images without changing their names, the images came in OK for me.

thanks

14

February 11, 2008

Hi Bill,
Glad you’re up and running then.
Relying on the EE control panel to upload the images individually sounds tedious anyways. Editing the image names ahead of time, tweaking the template etc. then uploading the whole image directory is probably going to be less trouble.
I’m using a combination of my hosts control panel running on Plesk has a file manager, it will upload a zip file and then extract the whole thing, or Expression Web (not recommended unless you are very familiar with frontpage extensions, which has no place in a php site really), but it comes in handy to get the template ready to go beforehand using search and replace for the paths & the CSS reformatting really is top notch like top style, and then uploading it via Plesks file manager.

15

February 11, 2008

tzCP,

Thanks for the input. I am still using the EE hosted trial and I have been told it is the only way you can upload files.

I am looking forward to batch-uploading and using some of the tools you mentioned when I upgrade to the full version of EE.

I have been working through the Boyink tutorial just to learn the basics at this point. (The clouds are beginning to clear.):-)

Looking forward to hearing from you in these forums in the future.

16

March 19, 2008

Hi Mike, looks like I just mixed Jessica.
Hey is there a way to have a dynamic category image, so that somehow it would always be the last image uploaded, or the freshest image in other words?
Some way to set a variable or anything, using the control panel and not uploading it w/ ftp? Just hit me w/ anything.

17
(Author)
March 19, 2008

Ty - the first thing that comes to mind is just using another weblog just for the images, tied to the same category group.  Then a weblog:entries tag will grab the latest entry/pic.

18

April 02, 2008

Hi, I can’t get the image resizer plugin to work when I use { site_url } -without the spaces- in the product_thumbnail field in my weblog. Traced it from the pi.imgsizer.php file and it looks like it uses the site_ure as a string, instead of replacing the site_url address. Here is my entry in the weblog:

{ site_url }images/interface/front_seats_tn.jpg.

and my imgresizer function:

{ exp:imgsizer:size src="{ product_thumbnail }” height="54" alt="{ title }” debug="yes"}

Can anyone help me with this?

Name:
Email:
URL:
Comments:

Remember me?

Shoot me an email when someone responds?

Enter this word:

Here:

GetBoyinked

Subscribe to Boyink.com