Webslices in Wordpress
Posted by beakersoft | Posted in Programming | Posted on 24-03-2008
13

One of the new features in the beta of Internet Explorer 8 is something called Webslices. These work in a similar way to RSS feeds, but allow you to subscribe to a section of a web page, as opposed to just a feed. The section of the page you subscribe to is a div with a class name of hsclice.
If a page contains webslice’s that can be subscribed to, a little purple icon shows in the IE tool bar, along with any rss feed options for the page. If you click on the webslice option a new link appears in the favorites bar, when you click on this you get the contents of the div. If the content of the div is updated, the item in the favorites bar shimmers and goes bold to inform you of the update.

So, I have written a small php script that can be used on a Wordpress blog to subscribe to the 7 last posts as a webslice. At the moment all I have is a script, but if people are interested I can turn it into a Wordpress plugin. You can download all the parts as a .zip file at the end of the post, but here is what it contains
- readme.txt – This file contains the bit of HTML code you need to insert in your index.php file (or where ever you want the webslice subscription option to show) and more detailed install information.
- webslice.php – The actual file that contains a div with the last 7 posts
- webslice.css – Style sheet for the php file
When you have downloaded the files, change the css to suite you, insert the div code into your page, upload to the server and away you go.
More Info on the script
When I first looked at adding a webslice to my Wordpress blog, I thought i would just place the hslice div around the existing previous posts section in my side bar. I went away from that idea though as I wanted the ability to format it differently, maybe add a graphic to the bottom etc so i went with an external file.
To make the page flag as having a webslice, but re-direct it to another page for the actual div, I used the class=”feedurl” option in the div. This just tells IE to look in a different place for the actual content. You can tell it to look at a page or an rss feed. The div containing all this info is hidden so it doesn’t interfere with any of the existing front page content.
The script it’s self is very straight forward. It just looks in your Wordpress DB for the last 7 (you can easily change this) posts , and puts them into n unordered list on the page, the formating is controlled by an external style sheet.
Please note this might not be 100% reliable. IE 8 is still in beta so its possible (but unlikely) the way it handles Webslices could change. I have also only tested this on one machine running the new IE, so it might not always work right. If you have problems get in contact and ill try and iron them out.
As I mentioned before if there is enough interest I might turn it into a plug-in
Edit: Since upgrading to the release version of Internet Explorer 8, any web slices I had suddenly stopped working. All I kept getting was ‘page cannot be displayed’ error in the space where the slice was. After much searching and head scratching I finally found the solution at http://support.microsoft.com/kb/969213
It turns out that Google Gears was stopping them from working, just disable the add on in IE and they start to work fine again
Download the script: wordpress_webslice.zip



This Blog about my (mis)adventures in the IT industry. My aim is to update this blog as often as possable with any tips, news or rants I might have. You can reach me at luke@beakersoft.co.uk

