Was this page helpful?

List Most Popular Pages Alternative


    Introduction

    This template will provide you will the most popular pages in a page tree per the view counts of those pages within a given path.  It allows you to control the number of items returned, as well as how deep to drill down the tree.  

    PERFORMANCE:  For best performance it is a good idea to keep your max results and depth as small as needed.

    History

    Version Date Author Description
     1.0 22/08/2009  rberinger  Initial template 
    1.0.a 28/08/2009 rberinger Change from using div id's to div classes
    1.1 19/03/2010 neilw Use @pageid to extract pages from wiki.tree(), for more reliable operation with pages with special characters in their names

    Requirements

    • This template requires Mindtouch Deki Version: This is pure dekiscript and I believe should work on all recent versions.  I have only tested this on Lyons.

    How do I install it?

    1. Create a template, call it "Template:TemplateName" (or rename as you desire).  You must have "unsafecontent" permission for this to work.
    2. Create a "Dekiscript" block on the template page (use the "Style" menu in the editor")
    3. Copy the code from the end of this page and paste it into the Dekiscript block.  To copy, click "expand source", then mouse over the top right corner of the source code, and click the "view source" button.  This will pop up a window with the source code.  Select all, then copy to clipboard.
    4. Make sure there isn't an extra blank paragraph after the Dekiscript block! Do this every time you edit!!!  
    5. Save.

     

    A quick note about the examples on this page

    For all the examples on this page, the code is shown before the working example.  The code is shown with the syntax extension, and looks like this:

    WhatsPopular{arguments}

    This means that the actual code on the page should be enclosed in a Dekiscript block.  If you want to copy the code from this page, then use the same procedure as described in steps 2-4 above. 

    How do I use it?

     Simply create a dekiscript block where you would like to have the Whats New list appear and make a call to the template.  See the example below.

    Arguments

    Name
    Type
    Default
    Description
     title str  Whats New!  This string will become the title of the results 
     path str  page.path 

    The path to serve as the starting point 

    max num 10 The maximum number of results to display
    depth num 10 The tree depth to look for pages (just like wiki.tree) 
    reverse bool true Reverse the sort order
    blockstyle str See Template Any valid in-line css.  Controls container that wraps entire template
    titlestyle str See Template Any valid in-line css. Control Title Section
    bodystyle str See Template Any valid in-line css. Controls the body or content section.

    Examples

     The following example limits the results to the top 5 most popular pages.  The styling also shrinks the template and centers within the container.

    WhatsPopular {
        title: 'Most Popular App Catalog Entries',
        path: 'app catalog',
        max: 5,
        depth: 1,
        blockstyle: 'width:50%; margin: 0 auto;'
    }
    Most Popular App Catalog Entries

     

     

    The following example limits the results to the top 10 most popular pages and will evaluate pages down 2 levels from the start page.

    WhatsPopular {
        title: 'Most Popular App Catalog Entries',
        path: '/DekiScript/FAQ',
        max: 10,
        depth: 2 
    }

    Reference(s)

     None.

    Credits/Special Thanks

    Everyone in the MindTouch Community Forum 

     Template/Extension Source Code

    /* WARNING
     * WARNING: this community-contributed template is not fit for production use as it performs a complete db-scan with every invocation
     * WARNING
     */
    
    // Parameters:
    //   title: The title text
    //   Path:  pathe to the starting page
    //   max:  Maximum number of items to list
    //   depth:  The level of sub page to evaluate
    //   reverse:  Reverse to sort order
    //   blockstyle:  Any valid in-line styles.  Affects container that wraps entire template
    //   titlestyle:  Any valid in-line styles.  Affects the title section
    //   bodystype:   Any valid in-line styles.   Affects the body section
    /*
      In a dekiscript block:
        WhatsPopular{ title: 'My Popular Pages', 
                   path: '/resources', 
                   max: 5, 
                   depth: 2, 
                   reverse: true, 
                 };
    
    Vesion History: 1.0 - Initial release
                    1.0.a - Changed from using div id's to div classes
                    1.1 - (neilw) Changed to using @pageid to find the pages from wiki.tree()
      
    */
    
    var ttl = ($0 ?? args.title ?? 'Whats New!');
    var path = ($1 ?? args.path ?? page.path);
    var maxnum = ($2 ?? args.max ?? 10);
    var depth = ($3 ?? args.depth ?? 10);
    var reverse = ($4 ?? args.reverse ?? true);
    var blockstyle = ($5 ?? args.blockstyle ?? '');
    var titlestyle = ($6 ?? args.titlestyle ?? '');
    var bodystyle = ($7 ?? args.bodystyle ?? '');
    
    
    var pageviews = 0;
    var pagelist = [];
    var pxml = wiki.tree(path,depth);
    
    foreach(var pid in xml.list(pxml, "//a/@pageid")) {
       let p = wiki.getpage(num.cast(pid));
       let pagelist ..= [ {title: p.title, uri: p.uri, viewcount: p.viewcount } ];
    }
    
    let pagelist = list.sort(pagelist, 'viewcount', reverse);
    
    <div class="whtspop" style=(blockstyle)>
    
        <div class="whtspoptitle" style=(titlestyle)>
            ttl;
         </div>
    
         <div class="whtspopbody" style=(bodystyle)>
    
            foreach(var p in pagelist) {
              if(__count >= maxnum) {break;}
    
                if(p.uri) {
                   web.link(p.uri, p.title); <span style="font-size: x-small;">;' - (' ..num.format(p.viewcount,'##,#') ..' Views)'; </span> <br/>;
              }
    
            }
                      
        </div>
    
    </div>
    
    
    // styles
    <html>
       <head>
          <style type="text/css">"
    
              div.whtspop {
                 width: 100%;
             }
    
              div.whtspoptitle {
                 background-color: rgb(234, 234, 234);
                 text-align: center;
                 padding: 2px;
                 font-weight: bold;
                 font-size: 16px;
                 border-style: outset; 
              }
        
              div.whtspopbody {
                 background-color: #FFF;
                 padding: 2px;
                 border-style: solid;
                 border-width: 1px;
                 text-align: left;
              }
           "
           </style>
       </head>
    </html>

     

    Disclaimers

    None.

    Was this page helpful?
    Tag page
    Viewing 1 of 1 comments: view all
    Just a note, I couldn't get the call to work until I had changed the Template type of the template page that I had created. It seems that in order to be called on a page, the template type has to be set as content.
    Posted 08:38, 9 Nov 2011
    Viewing 1 of 1 comments: view all
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by