I wanted to be able to have a list of a few of the books I'm currently reading available on my .Text blog. I've seen this feature on many other blogs, including MoveableType-based ones. So, being the crude “hack” programmer that I am, I threw a simple one together. I'd love to see someone take this under their wing and do it right... ;-)
The MyBookShelf.ascx control is a very simple set of code that displays the contents of an XML file “books.xml” using a XML stylesheet “books.xsl”. By default, it looks for the XML and XSL files in the website's root directory. If you want to change this, you can simply edit the MyBookShelf.ascx file with a text editor and change the relative paths for “books.xml” and “books.xsl”.
Click Here to Download an Example books.xml file. You can “tweak“ this by simply adding you're own information. You can create as many XML records as you want, the XSL is configured to display all of them. Based on the ISBN number of the book, it will hyperlink to the Amazon page for that book.
Click Here to Download the XSL file to display the books data. This is very bad programming (remember, I'm a hack), but the XSL has hard-coded in it the location for thumbnails of the book covers in JPG format. I just grab these straight from the Amazon site. A better way to do this would be to somehow programatically display them from Amazon's site. So, you'll need to change these to match a location where you have uploaded thumbnails of the book covers you want to display.
To add this to your .Text skin, you simply need to edit the page template of the skin that you're using and add some lines of code to display the control. Here's how:
- Make a good backup of the .Text skin you'lll be “playing” with. :-)
- If you want to edit the paths for the “books.xsl” and “books.xsl” files, do so by editing the MyBookShelf.ascx control. (Download the MyBookShelf.ascx file by clicking here.)
- Edit the PageTemplate.aspx file for the skin. At the top, you must register the new MyBookShelf control so that the PageTemplate.ascx file will be able to call it. To do this, just add the following line at the top of the file somewhere among the other control registrations you see: <%@ Register TagPrefix=”uc1” TagName=”MyBookShelf” Arc=”Controls/MyBookShelf.ascx” %><%@ Register TagPrefix=”uc1” TagName=”MyBookShelf” Arc=”Controls/MyBookShelf.ascx” %><%@ Register TagPrefix=”uc1” TagName=”MyBookShelf” Arc=”Controls/MyBookShelf.ascx” %>
- Next, you need to actually call the MyBookShelf control from the page template in the location you'd like it to be. To call the control, you would add the line: <uc1:MyBookShelf id=”MyBookShelf1” runat=”server”></uc1:MyBookShelf>
- The placement of the line above will determine where it shows up. I've posted an example PageTemplate.ascx file so that you can see what I'm talking about. (Download the PageTemplate.ascx example file by clicking here.)
- Upload the modified PageTemplate.ascx file to the root directory of the .Text skin you're using. Upload MyBookShelf.ascx to the “Controls” directory of the skin you're using. Upload your “books.xml” and “books.xsl” files to either the root of the website or to another location you've specified.
I've also built a similar control for displaying CDs. The info above is almost identical for it (open up some of the files and you'll see, so I'm just going to post all the example code in a zip file - click here to download it. The only major difference is that instead of keying off of the ISBN, I'm using something that seems to uniquely identify CDs on Amazon - an ASIN? Anyone know what this is?
Have fun...