Scott Hanselman

Home Page, Category, and Item Paging in DasBlog

July 9, '07 Comments [0] Posted in DasBlog
Sponsored By

We on the DasBlog still struggle with documentation (and we're always looking for folks who want to help). Any skinnable/themeable blog engine with templates and macros like DasBlog has literally hundreds of options that you can opt-in or out of.

DasBlog uses a macro engine with macros in the form of <% macro(param, param) %>. These macros go into two main template files (although there are others), called hometemplate.blogtemplate and itemtemplate.blogtemplate.

The first is not just the home page, but the whole basic layout of the blog. The second is the template for any one single blog post.

We recently added a couple of options for paging to DasBlog, but we haven't added them to all of our 16+ default themes, and if you have a custom theme - and most of you do - then you'll note get these new features unless you add a few things to your templates.

There's a couple different kinds of pagination, in an attempt to answer Jeff Sandquist's good question.

Home Page Paging

imageThere's "Older Posts" that you'd use to get to older ports from the home page. This takes the form of an "Older Posts" link usually at the bottom of your blog's main page, and a "Newer Posts" link if they are already off the main page. The URL will change to include a page parameter like: http://www.hanselman.com/blog/default.aspx?page=1

All this assumes that after someone has read the first page they'll want to continue reading backward in time. You can get that by adding these macros to your hometemplate.blogtemplate:

<div class="post-paging">
 <div class="previous-posts">
  <% DrawPostPagingPrevious() %>
 </div>
 <div class="next-posts">
  <% DrawPostPagingNext() %>
 </div>
 <div class="clear"></div>
</div>

The divs are, of course, totally optional. These are just what I use.

Category Paging

imageA lot of features are added after someone uses your product for years. I've got five years of blog posts now and I didn't have a problem with too many posts in one category in 2002, but now it's a problem. So, there's category paging, that appears only when you're on a category page and you've turned on category paging in your EditConfig.aspx.  To turn on category paging do two things, one, uncheck "Display All Entries in Category View and second, ensure there is a value in the "Entries per page" textbox.

image

The macro you'll need to add to your hometemplate.blogtemplate is:

<% DrawCategoryPaging() %> 

and I usually put in in the template TWICE, once above the "bodytext" macro and once below so folks can get to the next page regardless of if they're at the top or bottom of your page.

Single Item Paging (Navigation)

Finally, there's item paging. Not really paging, as it's navigation. It means being able to go from single post to single post. That's done by adding this to your itemtemplate.blogtemplate, usually at the top:

<%PreviousLink("&laquo;&nbsp;",40)%>
<%MainPageentryLink("Main", "|")%>
<%NextLink("&nbsp;&raquo;",40)%>

For the first and last macro, the HTML entities that are passed in are the characters that you want prepended or appended to the name of the previous and next title, and the number is the number of characters to show before truncating the title.  for the "Main" macro, the word passed in is the text to display to indicate the home page. I use the word "Main," myself. The second parameter is the separator.

image

Again, there's LOTS of cool stuff you can do with DasBlog that we are doing a lousy job of Documenting. If you want to get involved, join the DasBlog Developers Mailing List (Archives) and jump in. We're harmless.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. I am a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.