in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

echef

From the cluttered (and clustered) brain of Josef Nielsen... A great place for Food, Friends, and... uh... SharePoint of course!

Adding category titles to Blog sites (category.aspx)

I recently found an application of the Blog template that was a great fit, but needed the Category title listed on the top of the page when you click a category from the default page.  Normally, it is not visible anywhere except in the URL as a parameter, and in the categories of the posts listed. 

The primary content of the page is displayed by a ListViewWebPart embedded in a table in the aspx file.  It starts like this:

<table cellpadding=0 cellspacing=0 style='padding: 5px 10px 10px 10px;'>
           <tr>
            <td valign=top>
                <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="Left" Title="loc:Left"><ZoneTemplate>
<WebPartPages:ListViewWebPart runat="server" __MarkupType="xmlmarkup" WebPart="true" __WebPartId="{973762DE-3C5C-47B0-B80C-895B16BEDD6E}" >
<WebPart xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
  <Title>Posts</Title>
  <FrameType>None</FrameType>
  <Description>Use the Posts list for posts in this blog.</Description>

I added the following table row to the table above (before the webpart's row) to display it.

           <tr>
            <td><script language="javascript">
function getURLParam()
    {
        var strReturn = "null";
          var strHref = window.location.href;
        if ( strHref.indexOf("?") > -1 )
        {
            var strQueryString = strHref.substr(strHref.indexOf("?")+1);
            var aQueryString = strQueryString.split("&");
            for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
            {
              if (aQueryString[iParam].indexOf("Name=") > -1 )
              {
                var aParam = aQueryString[iParam].split("=");
                strReturn = aParam[1];
                break;
              }
            }
            var fields,i;
              fields = document.getElementsByTagName('DIV');
              for( i = 0; i < fields.length; i ++ )
              {
                if(fields[i ].innerHTML.indexOf("::") != -1)
                {
                     fields[i ].innerHTML = unescape(strReturn);
                }         
            }
         }
    }
    _spBodyOnLoadFunctionNames.push("getURLParam");
            </script>
             <div class="ms-sitetitle">::</div></td>
           </tr>

Note the use of the _spBodyOnLoadFunctionNames.push method to fire the script... This is documented on the SPD team's blog here.  This is so you can embed your javascript in master or aspx and have it execute correctly once the entire page is loaded.  I probably could have gotten away without it here, but used it to be safe. 

The script basically just looks for the <DIV> tag containing "::" and replaces it with the unescaped text from the "Name" parameter in the URL (Looks like http://MySharePointServer/sites/ICS/blog/category.aspx?Name=General%20Questions).  That is how the category is passed from the hyperlink to the category.aspx page.

Comments

 

Links (12/27/2007) « Steve Pietrek’s SharePoint Stuff said:

Pingback from  Links (12/27/2007) &laquo; Steve Pietrek&#8217;s SharePoint Stuff

December 27, 2007 7:36 PM

About josef.nielsen

I'm a long time computer nerd, living and loving technology wherever I can find it. I've recently shifted from a focus in MS SQL server, MSCS Clustering, and High Availability Engineering to focus on collaboration technologies, including SharePoint 2007. I recently moved from my long-time home in Seattle Washington to Salt Lake City.

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts