Skip to main content

Exclude pages from the popular pages list

This page applies to:MindTouch Responsive

Like the Display a list of popular pages tutorial, this tutorial shows you how to embed a list of most popular articles. However, this advanced version lets you exclude certain articles you might not want to appear. For example, you could use the steps in this tutorial to exclude your home page from the most popular pages list. After completing this tutorial, you will have the ability to display a list of your most popular articles with certain pages excluded. Additionally, you will be able to customize the appearance of the list using HTML and CSS and embed it in any MindTouch article.

Create your template

Start by creating a new MindTouch template where you can add the DekiScript to display your top popular pages. Use the following steps to create a new template:

  1. Choose Templates from the Tools menu.
  2. Click New Page.
  3. Double click Blank Page.
  4. Give your new page a title.

Note: ​The following example assumes your template has the title Template:PopularPagesExcludedWidget.

Add the DekiScript

Add the DekiScript that displays the most popular pages and set the list of pages to exclude. Perform the following steps:

  1. Click in the editor window of the template you just created to put your cursor there.
  2. Select DekiScript from the Styles menu.

  3. Copy the code below, paste it into the DekiScript block, and click Save.

    This code hides any pages titled "Home" and "Contact Us" from the popular pages list. To change which pages are hidden, replace Home and Contact Us with the titles of the pages you want to hide. You can also add additional pages by putting a comma after "Contact Us" and adding another page title on the next line.
    // Titles of pages to exclude.
    var popularPagesExcluded = [
        "Contact Us"
    // Number of pages to show in the list.
    var popularPagesNumber = 10;
    // Get the number of items to exclude.
    var excludesLength = #popularPagesExcluded;
    // Add the excluded items to the number of pages to show.
    var apiLimit = popularPagesNumber + excludesLength;
    // Build the popular pages API call.
    var uri = site.api & 'pages/popular' & { limit: apiLimit };
    var api = wiki.api(uri);
    <div class="widget-popular">
        // Loop through each page that the API returns.
        var count = 0;
        foreach (var pg in api['page']) {
            // Don't show more than requested.
            if (count >= popularPagesNumber) {
            // Get the current page's title and check for excluded titles.
            var title = pg / 'title';
            var found = false;
            foreach (var exclude in popularPagesExcluded) {
                if (exclude == title) {
                    let found = true;
            // Show pages that aren't in the excluded list.
            if (found == false) {
                let count = count + 1;
       / 'uri.ui', title);
                var viewcount = num.cast(pg / 'metrics/metric.views');
                <span class="viewcount">
                    " (";
                    " views)";

Customize the look and feel

Optionally, you can choose to add CSS to the Template to control how the popular pages list looks. Use the following steps to add CSS to the template:

  1. Edit the template you created. 
  2. Click in the editor window below the DekiScript block.
    (If the cursor appears inside the DekiScript block, press Shift+Enter to move the cursor outside the block.) 
  3. Select CSS from the Styles menu.

  4. Copy the CSS below and paste it into your CSS block and click Save.
    (You can change the values for the color, font size, and margin. You can also add additional CSS to this block.)
    .widget-popular .viewcount {
        color: #999999;
        font-size: 10px;
        margin: 0 0 0 10px;

Add your template to a page

Finally, you must embed the template in the MindTouch article where you want the list of popular pages to appear. For example, you might embed this list on the home page of your site. Use the following steps to embed the template in a MindTouch article:

  1. Edit the article where you want to embed the template.
  2. Place your cursor where you want to add the popular pages list.
  3. Select DekiScript from the Styles menu.
  4. Copy the DekiScript below and paste it into your DekiScript block. 
    If you did not name your template PopularPagesExcludedWidget, then change the code to include the correct template name.
  5. Click Save.


The code from this tutorial appears below. Compare this list to the unfiltered popular pages list and notice that the Home and Contact Us pages do not appear.


The following are places to go for more information on the API and DekiScript resources that were used to build this script.