Add to Technorati Favorites
Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Sunday, 12 August 2007

Making a 3 Column Blog

Blogger is great, we all know that - you can have a blog set up and running within about 2 minutes, and it'll look great just using the templates that they provide you with. If you're happy with the way things look then everyone will live in peace and harmony for ever and ever and ever. However, if there's something you want to change about the template, blogger can be a complete nightmare. Yes, everything is styled in CSS, which makes things a little bit easier, but if you don't know what's going on, you don't have a hope in hell of getting things to look the way that you want.

A couple of people this week have asked me how to make their default 2-column blogger template into a wider 3-column template - sounds pretty easy, but we are gonna have to get our hands dirty with the actual coding of the page to make it happen. Before we begin, a quick note: The blogger templates are set up so that they will be viewable on the smallest possible screen size (640x480) and people will not have to scroll horizontally. By increasing your width with 3 columns, the people using this resolution will have to do a lot of scrolling to see your content. However, looking at my stats for the last month for my blog, not one person was using this screen resolution (out of over 5,000 visitors), so this is a pretty moot point.

First of all, a bit of explanation on how the default blogger templates are set up. In order to get everything laid out on the page where they want it, they use Divs, and style them using CSS. Divs are a way in HTML of positioning a block of content exactly where you want it on the page. They're a little like tables, but instead of having to make sure that one table cell takes up x amount of space in order for another to appear in your desired position, with Divs, you can tell it an exact coordinate. Here's a diagram showing the Divs (and their names) on a default blogger template:


These are pretty self explanatory - the only one that may cause a bit of confusion is the outer-wrapper - this is basically a hold-all for all the other information contained within the page, and gives the divs contained within a reference for positioning. The divs will have different dimensions, depending on what default template you've chosen. This is how we want the template to look:

Here is where things start to get messy. The first thing we need to do is increase the width of the content-wrapper so that it can accommodate another sidebar on the left. The default sidebar is generally around 220 pixels wide, so we'll need to increase by this amount. Go into the Edit Template HTML page for your blog (dashboard>layout, then choose the Edit Template HTML tab at the top of the page). Now you need to find the part in the code that controls this outer-wrapper width - in the minima template this is about 1/3 of the way down the page - you're looking for:

#outer-wrapper {
width: 660px;
margin:0 auto;
padding:10px;
text-align:left;
font: $bodyfont;
}

This controls all the dimensions, margins and positioning for all your content in your blog. Some of the settings may be a little different, depending on your template, so don't be alarmed if this is the case. Change the width value to 780px. This is the maximum size width that people looking at your blog will be able to see without scrolling horizontally at 800x600 resolution (you need to allow 20px for the scrollbar on the right). While you're here, below the code you just edited, you'll see a section named #main-wrapper - change the float option in this section to center instead of left, so that it looks like this:

#main-wrapper {
width: 410px;
float: center;
word-wrap: break-word; /* fix for long text breaking sidebar float in IE */
overflow: hidden; /* fix for long non-text content breaking IE sidebar float */
}

This won't change much when people actually look at your page, but it will help you see things the way they're supposed to be in the layout editor. Now we need to change all the other divs so that they will fit with this new width. We'll deal with the header first, and work down. The header code is actually above the outer-wrapper code. This is what you're looking for:

#header-wrapper {
width:660px;
margin:0 auto 10px;
border:1px solid $bordercolor;
}


Again, change the width to 780px (we want the header to take up the entire width of the page). Same with the footer (further down the code):

#footer {
width:660px;
clear:both;
margin:0 auto;
padding-top:15px;
line-height: 1.6em;
text-transform:uppercase;
letter-spacing:.1em;
text-align: center;
}


Change the width to 780px again. Here's where things start to get interesting. The existing sidebar and the div that will contain the main content, we want to keep around the same size, and just budge them over enough to fit in another sidebar div. We need to copy and paste the existing sidebar-wrapper code to make the new sidebar to the left. Find this near the top of your code:

#sidebar-wrapper {
width: 220px;
float: right;
word-wrap: break-word; /* fix for long text breaking sidebar float in IE */
overflow: hidden; /* fix for long non-text content breaking IE sidebar float */
}


Change the width of this sidebar to 200px, then paste your new sidebar code directly underneath this one (it doesn't really matter where you put it, but it helps to keep all the wrappers together so you can find them easily if you need to. Change the values to something like this:

#sidebar-wrapper2 {
width: 170px;
float: left;
word-wrap: break-word; /* fix for long text breaking sidebar float in IE */
overflow: hidden; /* fix for long non-text content breaking IE sidebar float */
}


The float value just tells the div which side of the outer-wrapper to go to, you'll see on the other sidebar that this was set to go to the right. Now that we've set the style for our div, we need to actually create the div itself, so we have to move out of the CSS code block, and down to the HTML block, further down the page. Look for a block starting with this code:

<div id='sidebar-wrapper'>

Above this, paste the code for the new left sidebar:

<div id="sidebar-wrapper2">
<b:section class="sidebarLeft" id="sidebarLeft" preferred="yes">
<b:widget id="Profile1" locked="false" title="About Me" type="Profile">
</b:widget>
</b:section></div>

I've just added the "about me" widget to the left sidebar to give you something to fill the space in the layout editor, for when you come to add other widgets to this area, otherwise you'll have nowhere to drag your widgets to to add them to your new sidebar. You can remove this "about me" widget as soon as you've added another widget to the sidebar. Because you now have 2 "about me" sections, you'll need to delete the one for the right-hand sidebar, otherwise blogger will throw a tiz. Just delete this code

<b:widget id="Profile1" locked="false" title="About Me" type="Profile">
</b:widget>

from the right-hand sidebar div, which should now be just under the code you've just inserted.

All that remains is to copy the styles used for the right-hand side bar to the left one, so that they have a uniform style. Go back to the block of CSS code, and somewhere near the bottom you'll see a section specifically for the sidebar, starting with

/* Sidebar Content
----------------------------------------------- */


Here, you should see 4 or more styles relating to the right-hand sidebar, you need to copy these styles to the new left-hand sidebar by just adding the name of the sidebar to the list these styles apply to. So where you see

.sidebar {

replace it with

.sidebar, .sidebarLeft {

and where a certain element of the sidebar is changed, add the same element to the list for the left sidebar, so you might see

.sidebar ul {

change this to

.sidebar ul, .sidebarLeft ul{

likewise

.sidebar .widget, .main .widget {

becomes

.sidebar .widget, .main .widget, .sidebarLeft .widget {

and so on. Once you've copied all the styles for the right-hand side bar to the left-hand one, you should be pretty much done. You might want to fiddle around with the widths of the elements to make them fit better with your design, but apart from that most things should be fine. I would strongly suggest looking for a tutorial on CSS on the internet so that you understand fully what the code in your template is doing, and so you can edit it to look exactly the way you want it to without fear of breaking the template.

I hope you find this tutorial useful, and leave a comment if you have any problems with this or have a tip regarding this code, we're all here to help each other learn!

Tuesday, 26 June 2007

Step by Step: Making a Podcast, Pt. III

Now that we've got an mp3 file stored somewhere on the net, we need to create our XML file, so that iTunes and other podcatching software knows where to find and download this mp3 from.

First, let's have a look at what an XML file actually looks like. Below is some typical XML podcast code:

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<channel>
<title>Jim's Scottish Podcast</title>
<link>http://www.jim-mcjim.com
</link>
<language>en</language>
<copyright>Jim McJim, 2007</copyright>
<itunes:subtitle>A weekly changing podcast on the ever changing weather of Scotland</itunes:subtitle>
<itunes:author>Jim McJim</itunes:author>
<description>Have you ever wondered what the weather was like in Scotland last week? Wonder no more as Jim McJim takes you on a whistle stop tour of Scottish Weather through the ages.</description>
<itunes:image href="http://www.jim-mcjim.com/jimsporran.jpg"> </itunes:image>
<itunes:owner>
<itunes:name>Jim McJim</itunes:name>
<itunes:email
>imjim@jim-mcjim.com</itunes:email>
</itunes:owner>
<itunes:category text="Places &amp; Travel"></itunes:category>
<itunes:keywords>Scotland, Weather, Jim McJim, Rain</itunes:keywords>
<item>
<title>Aberdeen</title>
<itunes:author>Jim McJim</itunes:author>
<link>http://www.jim-mcjim.com/aberdeen26062007.mp3</link>
<itunes:subtitle>A quick look at Aberdeen's greyness through the ages.</itunes:subtitle>
<description>Don't be fooled by Global Warming and El Nino, Aberdeen has always had crummy weather, as we set out to prove in this weeks installment of Jim's Scottish Podcast. Jim is always taking suggestions for where to do his Scottish podcast on next, and he'll happily tell you exactly how rainy it's been just about anywhere in the country. Contact Jim on imjim@jim-mcjim.com.</description>
<enclosure url="http://www.jim-mcjim.com/aberdeen26062007.mp3" length="57099128" type="audio/mpeg"/>
<pubDate>Thu, 19 Apr 2007 11:14:18 GMT</pubDate>
<itunes:duration>59:12</itunes:duration>
<itunes:keywords>Scotland, Aberdeen, Rain</itunes:keywords>
</item>
</channel>
</rss>

At first it looks like a complete mess, but if you look closely, it actually makes a lot of sense - XML was designed so that computers could interpret it, but it was also designed so that the average human could look at it and see exactly what was going on as well. You could pretty much copy and paste that snippet into a blank notepad document, change it to the details you need, and use it as your XML if need be, without even reading the next part.

If you've programmed a web page using HTML before now, the XML will appear very familiar to you - the difference between them though is that whilst HTML describes everything that goes on in a page (including pictures, formatting, backgrounds, tables etc.), XML only describes the data, and leaves the formatting up to the page hosting the XML document, or the program or device it's being shown in. You'll notice, like HTML, that each snippet of data is held between two "tags", which describe what data is contained in that tag. There is always an opening tag: <data> , and a closing tag: </data>

Now we know the basics of an XML file, let's pick apart the above example, tag by tag, so that we can better understand what's going on with this file.

  • <?xml version="1.0" encoding="UTF-8"?>
    This tag must always be at the start of every podcast XML file - it basically just tells any program reading this file that it's an XML file. Never change this tag, as anything trying to "tune in" to your podcast will just get confused.
  • <rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">...</rss>
    This is what is known as the "namespace" tag. Every XML file must have one, and it tells any program reading the file what each tag means. For just a standard podcast, use this tag, as it includes all the information needed for the iTunes tags, as well as standard podcast tags.
  • <channel>...</channel>
    This is where the podcasting magic begins. This tag just tells us that everything between these tags will be a new podcast. You can put more than one channel into an XML file, but I wouldn't recommend it. You'll notice that just about everything else in the file is enclosed in these tags.
  • <title>Jim's Scottish Podcast</title>
    This is the title of the pocast, as it will show up in the podcasting software.
  • <link>http://www.jim-mcjim.com</link>
    This is just the website associated with the podcast. If there's the option to link to a website in the podcasting software, this is where it will take you.
  • <language>en</language>
    This is the default language for the podcast. In this case it tells us that it will be standard English. We could be more specific and set this instead to "en-gb", which software would interpret as British English. There is a list of different values for different languages here.
  • <copyright>Jim McJim, 2007</copyright>
    Pretty self-explanatory, who holds the copyright for this podcast. This might be a single person, as in this example, or it might be a company.
  • <itunes:subtitle>A weekly changing podcast on the ever changing weather of Scotland</itunes:subtitle>
    The iTunes subtitle: gives an annotated description of what the podcast is about in iTunes. There's a couple of other podcast directories that read this value as well. It's best to be as concise as possible when setting this, as it may be the deciding factor as to whether someone listens to your podcast, or passes it by.
  • <itunes:author>Jim McJim</itunes:author>
    Another iTunes specific tag - this is the Author or main producer of the podcast. This will usually be the same as the copyright holder.
  • <description>...</description>
    This is where you can be as descriptive as you want on what your podcast is about. iTunes shows this description on the individual podcast page, as do most podcasting websites.
  • <itunes:image href="http://www.jim-mcjim.com/jimsporran.jpg"> </itunes:image>
    This is the image that iTunes will show in the podcast charts, and on the individual page describing your podcast. This must be a JPEG, and it is most effective if it is square. Your podcast will get much more exposure if you have a decent image.
  • <itunes:owner>
    <itunes:name>Jim McJim</itunes:name>
    <itunes:email
    >imjim@jim-mcjim.com</itunes:email>
    </itunes:owner>
    More iTunes specific owner information. Again, this will usually be the same as the copyright holder's details.
  • <itunes:category text="Places &amp; Travel"></itunes:category>
    This is the category that your podcast will be placed under in the iTunes directory. Some other podcasting websites also use this. There's a full list of what you can set this value as here.
  • <itunes:keywords>Scotland, Weather, Jim McJim, Rain</itunes:keywords>
    Words that people might use to search for your podcast in iTunes. Try to think of as many words as possible, but keep within the realms of what your podcast is about. The more words you choose, the further down the "relevance" list your podcast will appear, so be as specific as possible. Seperate each term with a comma.
  • <item>...</item>
    This is the next tag you need to pay attention to. Everything between a set of <item> tags describes one episode of your podcast. You can many item tags in one XML file. You'll notice that a few of the tags contained within this one are the same as for the podcast itself - these fulfill the same function, but instead of describing the podcast now, they're describing an individual episode.
  • <link>http://www.jim-mcjim.com/aberdeen26062007.mp3</link>
    For each episode, include a link tag which is the URL of the mp3 file associated with this episode. This will allow people looking at the podcast on websites to go straight to the mp3 file, and stream or download it. It's less helpful for an episode link tag to go to the podcast website.
  • <enclosure url="http://www.jim-mcjim.com/aberdeen26062007.mp3" length="57099128" type="audio/mpeg"/>
    This is where the real magic happens - the tag which tells iTunes and other podcasting software where the episode mp3 file (or video file) is contained. Change the value in the quotes next to url to the URL where you stored the mp3 file. The length value is the size (in bytes) of the file (right click the file in windows explorer, and go to properties so get this value). Type is the type of file this is, in most cases this will be an mp3 file, but it could be a video file. The following table shows other file types values this might be:
    File Type
    .mp3 audio/mpeg
    .m4a audio/x-m4a
    .mp4 video/mp4
    .m4v video/x-m4v
    .mov video/quicktime
    .pdf application/pdf
  • <pubDate>Thu, 19 Apr 2007 11:14:18 GMT</pubDate>
    The date this episode was produced. It must be kept in this exact format, or your episodes will most likely end up in the wrong order.
  • <itunes:duration>59:12</itunes:duration>
    The duration of the episode, in hours:minutes:seconds. In this case the episode is 59 minutes and 12 seconds long. It's important to set this right, otherwise iTunes will list your episode as having no duration.
  • <itunes:keywords>Scotland, Aberdeen, Rain</itunes:keywords>
    Keywords applicable to the individual episode.
  • </item>
    </channel>
    </rss>
    These close the episode, channel, and XML file, respectively. Remember that after the closing item tag, and before the closing channel tag, you might have one or more item tags, each with their own title, description, enclosure etc. tags within them, and all describing seperate episodes.
This is pretty much a bare bones XML file, which as stated earlier, you could copy and paste into notepad, change the values so they are applicable to your podcast, save it as "podcast.xml" (or similar - just make sure that your filename ends ".xml" - in the "save as type" chooser in the "save as..." dialog box, you might want to change it to "*.*" instead of "*.txt", as this will ensure that notepad doesn't change the file extension), and upload to the web. This is the bare minimum of tags that are required to get your podcast into most podcasting directories, and iTunes, but there are other tags as well, these are listed in the Apple technical specifications here. Some of the iTunes tags just double up on tags that are already described here though, which is why I've chosen not to include them. iTunes is big enough and ugly enough to work out what should go where without you having to put the information in twice.

Next I'll take you through the process of validating your XML file to make sure it works in iTunes and other podcasting software, before we list it in the iTunes directory.

Monday, 18 June 2007

More MySpace Censorship (and how to get around it!)

Whilst Marisa was lurking my MySpace page just now, She found that clicking the link that takes you to my blog here, just takes you straight back to the MySpace homepage. How strange. I thought that perhaps I'd typed the address of my blog in wrong when editing my profile, but when I went back into edit mode, I found that the URL I'd typed in had changed completely to some address at msplinks.com . So I edited my profile back to the original address and saved it again. Only to find the link was changed instantly by MySpace to the same address, which took you back to the MySpace homepage.

So I did a little research. Apparently MySpace started using Msplinks.com to stop spammers leaving comments on your page. Fair enough, but that's no reason to stop me linking to my own blog, even if that blog does exist somewhere outside MySpace's realm of shit advertising. Basically it's just another form of MySpace censorship, and if people are stupid enough to add people who are clearly spammers to their friends list, then they deserve a load of comments spam in my opinion.

But how to get MySpace to link to my blog? Well, it looks like Msplinks.com blocks any links to blogger sites, so the simple answer is to set up a redirect from another site. In my case, I have space at Google Pages, so I set up a fake page there which just included nothing but this script in the body of the page to redirect to my blog:

<script>self.location="URL of your blog here";</script>

Then just link to this page from MySpace instead of your actual blog URL, and you'll be good to go. MySpace, who's the stupid idiots now?

Update: It seems that MySpace have found out about this workaround, and have since blocked it. If MySpace are so serious about censoring it's users, and blocking links to competitors websites (which seems a very childish thing to do), I no longer want to be associated with it. I think I may have found a site that has everything I was looking for in MySpace: Virb, have a look round and see what you think - personally I think it looks a much more friendly, well designed, and less money driven alternative, and I shall be moving there as soon as I've made my profile!