Saturday, August 29, 2009

Centering an Amazon aStore

To center the aStore, log in to your Amazon affiliate account and click the aStore tab on your home page. Click the Edit button to open the aStore builder wizard. In Step 2, Color & Design, click Edit CSS.

In the big empty box on the left of the screen type the following CSS:

body {text-align: center;}
#wrap {text-align: left; margin: 0 auto;}

The #wrap div encloses the entire aStore and its width is declared in the aStore's Global style sheet, so there is no need to repeat it.

Note that using text-align to center block elements is obsolete, and NOT recommended when a web page has a valid doctype. However, the aStore lacks a doctype, causing browsers to relay on quirks (ancient browser) mode to render the web page. To center the #wrap div in this situation, the old text-align hack is necessary in some browsers.

When a valid doctype is present, all that is needed to center a block element of known width is "margin: 0 auto;". Learn more about doctypes at:

Friday, August 28, 2009

Making an aStore narrower

"Help! My aStore is cut off on the right! How do I make it narrower?" This question is very common on the Amazon affiliates discussion board. The answer is to take advantage of Amazon's option for adding your own "overriding CSS" to the aStore style sheet.

To do this, edit your aStore. In step 2, Color & Design, click Edit CSS. Then enter your own CSS in the big empty box on the left side of the screen. A quick and painless way to remove 48px from the width of the aStore is to enter the following CSS in the Global style sheet:

body {margin: 0;}

This style removes the default 24px margin from the aStore <body> tag, moving the content flush top and left in the <iframe> container.

To make a narrow aStore, some CSS styles have to be changed or added in each tab of the CSS sheet editor. You can do it yourself by starting with the Global tab and working your way through the tabs for Category, Detail Page, Listmania, Reviews, and Shopping Cart, or you can take the easy way out and start with a Shared Theme.

On the Color & Design page, click Shared Themes. Unfortunately, there is no way to search the themes, but you can browse through them, and preview any that have the word narrow or skinny in their titles. As a learning exercise, I posted three shared themes, Narrow Earth, Narrow Blue Centered, and Narrow Red Centered. These themes are each 680px wide, so they will fit in the center column of many web pages.

Remember to jot down your color preferences (or take a screenshot) before you apply a shared theme so that you reselect them afterwards. You can also reselect a previous color scheme from the dropdown list without affecting CSS in the shared template. The same thing is true for font styling (found in some templates) that is unrelated to adjustments for element widths, padding, and margins.

If you later decide to go back to a standard theme, you can. Just remember to select "Edit CSS" again and manually delete all user-added styles in the CSS tabs.

As noted in one of the comments, if you use a sidebar search widget with Amazon categories, it needs to be about 10px narrower to avoid cutting off the arrow next to the dropdown category selection box. I will update my Narrow templates to add the CSS for that. I overlooked the search widget because I use hand-picked products instead of Amazon categories.

There are alternatives to the aStore if space is tight. The "My Favorites" widget can be made narrow enough to fit in a sidebar and is automatically paged. Likewise, the "Recommended Products" widget can be vertically oriented. The aStore widget can be made long and narrow or wide and narrow. It displays items from the aStore's first category, so control over the contents is indirect.

I hope this tip saves you some time getting your aStore integrated into your web site. In turn, if you make a great theme, you might want to allow it to be shared, too.

Friday, August 14, 2009

Line breaks in blogger

Since this post, Blogger has introduced changes to its "new editor" that affect the way line breaks and other HTML are handled. Under Post Options, there are new choices for HTML and Compose. For more information, read the overview of the new post editor to avoid confusion! The HTML option to "Ignore newlines" works fine. Nevertheless, I've found that switching to Compose from HTML and back DESTROYS paragraph tags no matter which "Compose" option is selected. That is, "Interpret typed HTML" removes all <p> tags and replaces breaks with <br />. Selecting "Show HTML literally" changes tags to viewable text. If you have to switch, copy the post to the clipboard first so that you can restore the mangled HTML! Previewing from the HTML tab seems to work alright, though.

I didn't see this coming, but blogger's handling of line breaks is the one thing I would like to change most in an otherwise very nice program. The conversion of each line break to a <br /> tag works relentlessly and saves time when typing a series of simple paragraphs. But the convenience has a dark side.

The lack of real <p> tags is semantically incorrect and hard to overlook. Even so, it seems like a a reasonable sacrifice for ease of use. Until, one day, unnecessary <br /> tags inevitably appear in the middle of scripts, before <pre> tags, between list items in unordered and ordered lists, and in great goopy multiples in pasted content. There's no fix except to edit the HTML and remove every last line break that adds unwanted space.

After laboriously editing several long posts that looked silly and disconnected all spread out, I pulled the plug on "Convert line breaks" and updated all my posts. If you turn off auto line breaks and fail to update your old posts, it's not a pretty sight, at least with the old editor. Once you've made your choice, it's a commitment to use the HTML editor going forward, except for very rare occasions.

What happens if you fall of the wagon and use Compose?

I haven't tested the new blogger editor extensively, but its behavior is not as "hands-off" as the old editor, which left existing paragraph tags alone. In fact, it carried on with new <p> tags in a test draft post that I started in HTML view and continued in Compose mode, as though it wanted to please. However, if you start out in Compose mode, it adds divs where there are line breaks. Whenever I edit a complicated post, I always paste it into Ultra Edit for safekeeping and tidying up.

After I switched to the new editor, I noticed that it does nuke <p> tags if you switch from the HTML editor to Compose. If I need to switch, I copy and paste code to Ultra Edit (although any text editor is fine), use Compose to add an image or whatever, switch back to HTML mode and paste my "good" code over everything but the new addition. This is faster than replacing non-semantic divs with paragraph tags. I really do use the HTML editor almost 100% of the time!

My wish is for an editor in which Enter inserts a paragraph tag and Shift-Enter, a line break. Maybe that's too much ask. Couldn't bloggers who never type anything but plain text into their posts keep the current option? Can we have our cake and eat it too? I'm hoping.

Monday, August 10, 2009

Product preview in a blog post

Notice: Amazon Product Previews stopped working in Blogger here on June 4, 2010. The problem appears if a jQuery script tag (either 1.2.6 or 1.3.2) is included in the Blogger template. Amazon uses a customized version of jQuery 1.2.6 and a lot of scripting for the previews. I want to keep my jQuery script tag, so the information provided below will work in Blogger, as illustrated by the screenshots, as long as it doesn't collide with the standard jQuery library.

When you use Amazon's Link Builder to create a text or basic image link, instructions for adding the product previews script to a standard web page are displayed at the bottom of the "Get Link" step. You can also add the same script to the blogger template or to a single post.

Here is an example of an Amazon text-only link with product preview:
Beowulf and the Beowulf Manuscript (rev sub edition 1997). Mouseover the link to see a box with the book cover image, customer rating, and price. The preview should look like the screenshot below.

Screenshot of preview with text link in Firefox 3.5:

Be aware that product previews work with Internet Explorer and Firefox. In Chrome and Safari(win), both WebKit browsers, the preview box might not display or appear as an empty box. In Opera, the preview does not display at all.

book cover image: The Beowulf Manuscript
Product previews with image links, such as the example at left, work in Firefox and Internet Explorer. I have had a recurring problem with IE, in that the product preview displays and then disappears unless instantly grabbed with the mouse. The product preview should look like the screenshot below.

Screenshot of preview with image link in Firefox 3.5:

To include the product preview script in a post, click the "Edit Html" tab in the blogger editor and paste the script at the end of your post. Important: Remove any line breaks in the pasted script because they magically become <br /> tags that will cause errors. Then change the ampersand (&) in the script's "src" attribute to &amp;.

The script should look like this, with the script tag all on one line:

<script src="http://www.assoc-amazon.com/s/link-enhancer?tag=yourTagID&amp;o=1" type="text/javascript"></script> <noscript><div><img alt="" src="http://www.assoc-amazon.com/s/noscript?tag=yourTagID"/></div></noscript>

The code has been added to this post, so it can be seen with "View Source". However, since I have also added the same script to the blogger template, product previews will display in any post that has Amazon text links in both Internet Explorer and Firefox, or in Firefox with image links. Please see this related post for more information about adding the product previews script to the blogger template.

Sunday, August 2, 2009

Add an Amazon image link in a post

I like book cover images because they provide clues about genre, tone, or publisher that help me decide if I want to click for more detailed information. Used sparingly, cover images stand out as spots of color in a sea of text. I use a method of creating image links that is easy for me. You may find a method that works better for you.

book cover image

Here's an example of an image link:
The novel American Gods by Neil Gaiman, is a SciFi/Fantasy tale about how Old Norse gods migrated to the new world, exist among us disguised as humans, and battle the new gods of World, Money, Internet, etc. The invisible life of an ordinary human named Shadow becomes both tragic and heroic after he signs on as Odin's aide, sees more than he should, and asks life's big questions.

Task Summary

  • Log in to Amazon so that your affiliate ID will be embedded into links you make with the Site Stripe widget or affiliate bookmarklet.
  • Find the product page for your link destination
  • Copy the product image to your computer
  • Upload the image to a free image storage site (such as PhotoBucket) or to your web hosting server
  • Add an img tag to your blog post, and set its src attribute to the location of the image file
  • Create and copy the product link, then wrap the image in the <a> [anchor] tag

Procedural Details

1. After you find the product page for your link, copy the product or book cover image to your computer. There are two methods for getting the image.

  • Method 1 - Use Amazon Site Stripe
    If you use Site Stripe, click, "Link to this page." When the link builder wizard opens, right-click the image and save it to your computer, anywhere that's easy to remember. It's okay to change the image filename to something memorable. Images may not be altered except to resize.
  • Method 2 - Add the product ASIN to the following link pattern:
    Size (approx) Link
    Small 50x75 images.amazon.com/images/P/ASIN.01.THUMBZZZ.jpg
    Medium 107x160 images.amazon.com/images/P/ASIN.01.MZZZZZZZ.jpg
    Large 317x475 images.amazon.com/images/P/ASIN.01.LZZZZZZZ.jpg

2. Get the product link using Site Stripe or the Affiliate Bookmarklet. The shortest link follows this pattern:

http://www.amazon.com/dp/ASIN/?tag=YOURTAGID
Plug in the ASIN and your affiliate tag:
http://www.amazon.com/dp/0060558121/?tag=myTag-20

If you use Site Stripe, click "Link to this page" at the far left of the toolbar. The link wizard makes a link that you can copy and paste. To make the link shorter, change gp/product to dp, and delete everything after the ? except your tag.

The Completed Link

The finished image link will look something like the one for American Gods, shown above. I've added an inline style to the img tag to float it left and wrap text around the right side:

<a href="http://www.amazon.com/dp/0060558121/?tag=myTag-20">
<img style="display:block; float:left; margin:0 15px 15px 0; 
height:160px; width:107px;" 
src="http://greenetea.com/images/amergods.jpg" 
alt="book cover image" /></a>

In practice, it's better to add a style for .floatleft to your style sheet that you can reuse whenever you need to float an image left. A .floatright style would be the same except for the horizontal margins. The right margin would be 0, and the left one, 15px. The shorthand CSS for margins is clockwise: top right bottom left.

Blogger's upload image feature

Another way to add an image link to a post is to click the picture icon in blogger's post editor. Follow the prompts to upload your image to Picasa, where you have 1GB of storage. Then, in blogger, edit the image link's href attribute to point to the Amazon page instead of Picasa. Here's the result:

As you can see, using blogger with Picasa works fine with the medium-sized Amazon product image. I don't use this method because I have a website where I can corral and control images. If I were creating a shared photo album, Picasa would be a fitting choice for that purpose

I hope these instructions make sense of a task that should be simple.