Skip to main content
NICE CXone Expert
Expert Success Center

Exclude pages from the popular pages list

Applies to:
All MindTouch Versions
Role required:
Author
Embed a list of most popular pages, with an option to exclude certain pages.

For example, you could use the steps in this tutorial to exclude your home page from the most popular pages list. Additionally, you can customize the appearance of the list using HTML and CSS and embed it in any Expert article.

Create your template

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

  1. Navigate to Site toolsDashboard > Site Administration > Template Directory (/Template:).
  2. Navigate to Template:Custom.
  3. Click New.
  4. Give your new page a title.

Do not modify or add any templates in Templates:Expert

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 = [
        "Home",
        "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">
        <ul>
        // 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) {
                break;
            }
            // 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;
                    break;
                }
            }
            // Show pages that aren't in the excluded list.
            if (found == false) {
                let count = count + 1;
            <li>
                web.link(pg / 'uri.ui', title);
                var viewcount = num.cast(pg / 'metrics/metric.views');
                <span class="viewcount">
                    " (";
                    num.format(viewcount,"###,###,###");
                    " views)";
                </span>
            </li>
            }
        }
        </ul>
    </div>
    

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 Expert 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 an Expert 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.
    template("PopularPagesExcludedWidget");
    
  5. Click Save.

Demo

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.

  • Was this article helpful?