In our previous posts on Ultimate DNN Blog Module – SunBlogNuke hacks, we discussed the incredible flexibility of  SunBlogNuke, which is one of the biggest reasons for its popularity among bloggers worldwide. In particular, from v4.0 we introduced the custom fields feature, which let users create variables and add custom values to them, are  one of the reasons for SunBlogNuke’ flexibility and endless possibilities.

In this tutorial, we will compile a list of useful things that you can do with custom fields in SunBlogNuke (if you are not heard of custom fields feature please refer to the initial guideline firstly - Extend DNN Blog With Custom Fields). Among them are re-defining the <title> tag of every post and linking to external resources instead of the blog post. More will be included later. Please stay tune. :)

1. Re-Define The <title> Tag

The problem. On blogs, as on every other type of website, content is king. And SEO is very important for achieving your goals with traffic. By default, SunBlogNuke have an optimized <title> tag retrieved from the title of the post when visiting the post detail. Some clients requested to override <title> tag with different value so now we would like to show you how to do it with a custom field.

The solution. Follow up the steps below:

  1. When writing a new post, simply create a custom field called metaTitle, and enter your custom title as a value.
  2. Enter the Customize panel (you can find it in the blog admin panel) and check out the current theme in 'Theme' tab. Make sure you did not choose the default theme because it is not deny to do any modifies or customizations.
    Note that if you switched the theme you need to refresh the page so that the correct theme view files are retrieve into ‘Theme Editor’ panel.
  3. Enter 'Theme Editor' panel and select the detailview.ascx. Then append the following codes as follows:
    <script runat="server" type="text/VB">
        Protected Overrides Sub OnLoad(ByVal e As EventArgs)
            If Not Page.IsPostBack Then
                Dim title As String = GetCustomField("metaTitle")
                If Not String.IsNullOrEmpty(title) Then
                    CType(Page, CDefault).Title = title
                End If
            End If
        End Sub
    </script>
    Have a look at the screenshot below (click to zoom):

    theme editor

Code explanation. When visiting the active post, the code looks for a custom field called metaTitle. If one is found and it is not empty, its value is displayed as the title. Otherwise, it uses the post’s title.

2. Link To External Resources

The problem. Many clients have asked me the following question: “How can I link directly to an external source, rather than creating a post just to tell visitors to visit another url or website?”. In our side, we also encountered the same similar requirement, for example, the tutorials in the document page is listed by titles in the sider bar but  sometimes we would like to summary it in the team blog so that clients or users may be interested in new published tutorial and it also will build navigation with traffic. Yes, we don’t want to build the duplicate content just to direct to the permalink of the original tutorial.

The solution to this problem is to use custom fields. Let’s see how we can do that.

The solution. Actually the process is the same but with different codes:

  1. When writing a new post, simply create a custom field called external-link, and enter the external url as a value.
  2. Enter the Customize panel (you can find it in the blog admin panel) and check out the current theme in 'Theme' tab. Make sure you did not choose the default theme because it is not deny to do any modifies or customizations.
    Note that if you switched the theme you need to refresh the page so that the correct theme view files are retrieve into ‘Theme Editor’ panel.
  3. Enter 'Theme Editor' panel and select the basicview.ascx. Then append the following codes as follows:
    <div class="post">
        <%
            Dim link As String = Entry.Link
            Dim externallink As String = GetCustomField("external-link")
            If Not String.IsNullOrEmpty(externallink) Then link = externallink
        %>
        <h2 class="post-title"><a rel="bookmark" href="<%=link%>"><%=Entry.Title%></a></h2>
        <!-- OTHER CODES BELOW -->
    </div>

Code explanation.  Basically, if a custom field called external-link is found, then the title link will lead to the external url rather than the blog post. If the custom field isn’t found, the function simply displays a link to the post itself.

As usual, please let me know your thoughts with leaving your comment below and make sure to enter your suggestions for improving our product at support forum.