These days, I have setup the WAP site for Wangjianshuo’s Blog. I can get the latest comments on my web site and the total hit count from my mobile. I’d like to share the source code and steps with all blog users – especially for MovableType owners since you can convert your web site to WAP site with the code I provide.
How to access the WAP site
If you have a WAP-enabled mobile, please visit the following web site:
http://home.wangjianshuo.com/wap/
Here is the two images (left is the home page displaying all the comments and the right picture shows the hit counter)
The above are the simulated OT301 screen using UP.Simulator. I hope I can give you a picture of the page on my Alcatel OT715 one day.
Note: If you click the link above in Internet Explorer, you will not see the page. Instead, you are prompted to download the page, since it returns “text/vnd.wap.wml” as content type which cannot be proccessed by Internet Explorer.
The WAP page – WML file
If you save the page to your local disk and open it in notepad, you will see the following codes:
<?xml version=”1.0″?>
<!DOCTYPE wml PUBLIC “-//WAPFORUM//DTD WML 1.1//EN” “http://www.wapforum.org/DTD/wml_1.1.xml”>
<wml>
<card id=”index” title=”Wangjianshuo’s blog”>
<p><a href=”index.asp?id=353″>Jian Shuo Wang</a></p>
<p><a href=”index.asp?id=352″>p1gs1ck</a></p>
<p><a href=”index.asp?id=351″>KLN</a></p>
<p>* <a href=”hits.cgi”>Hits</a></p>
</card>
</wml>
After you click the *Hits link, you get the following WML code:
<?xml version=”1.0″?>
<!DOCTYPE wml PUBLIC “-//WAPFORUM//DTD WML 1.1//EN” “http://www.wapforum.org/DTD/wml_1.1.xml”>
<wml>
<head>
<meta forua=”true” http-equiv=”Cache-Control” content=”max-age=0″/>
</head>
<card id=”hit” title=”Page Hit”>
<p>Page hits: 127502</p>
<p>[<a href=”index.asp”>Back</a>]</p>
</card>
</wml>
Code behind the sceen
I used an ASP file to do the job. You can easily convert it to Perl or PHP code. If you are using MovableType, follow the steps below to create a WAP index template.
1. Open MovableType console and open the blog you are editing.
2. Click “Templates” on the left navigation bar.
3. Click “Click new index template” in the Index Template section.
4. Enter “WAP Index” in Name field and “WAP/Index.asp” in the Output file field.
5. Use the code below in the Template body field.
6. Save the template and rebuild. You will have the WAP page at WAP/index.asp.
<%
‘
‘ Copyright 2003 Jian Shuo Wang
‘ URL: http://wangjianshuo.com
‘ Author: Jian Shuo Wang
‘ Created: March 18, 2003
‘ Description:
‘ This page displays the latest comments
‘ on any mobile phone supporting WAP.
‘
%>
<%
Response.ContentType=”text/vnd.wap.wml”
If Request(“ID”) = “” Then
Response.Expires = -1
End If
%>
<%
‘
‘ The standard header every card need
‘
%>
<?xml version=”1.0″?>
<!DOCTYPE wml PUBLIC “-//WAPFORUM//DTD WML 1.1//EN” “http://www.wapforum.org/DTD/wml_1.1.xml”>
<wml>
<%
Select Case Request(“ID”)
‘ =================================
‘ Comment content
‘ =================================
%>
<MTComments lastn=”5″>
<%
Case “<$MTCommentID$>”:
%>
<card id=”index” title=”<$MTCommentAuthor$>”>
<$MTCommentBody$>
<p>- by <$MTCommentEmail$> at <$MTCommentDate$> from <$MTCommentIP$></p>
<p>[<a href=”?”>Back</a>]</p>
</card>
</MTComments>
<%
Case “”:
‘ =================================
‘ Homepage – Comment Index
‘ =================================
%>
<card id=”index” title=”<$MTBlogName$>”>
<MTComments lastn=”10″>
<p><a href=”index.asp?id=<$MTCommentID$>”><$MTCommentAuthor$></a></p>
</MTComments>
<p>* <a href=”hits.cgi”>Hits</a></p>
</card>
<%
Case Else:
%>
<card id=”index” title=”Wangjianshuo”>
<p>Something wrong with the page</p>
<p><a href=”?”>Back</a></p>
</card>
<%
End Select
%>
</wml>
Comments on the code
1. Response.ContentType=”text/vnd.wap.wml” must be included since it let the WAP browser understand it is a WML content since it cannot be judged from the .ASP extension.
2. It may need some modification before it can work on your site.