Remove Duplications

By James Kanjo James Kanjo

Description

Sometimes, if you are using the ListPages module for data presentation, you may list duplicate results. In such cases, you can use this special add-on to remove all duplicated instances, and place them in a list.

This is the code that does all of the hard work. You should never need to use this code.

<html><head><title>Remove Duplications</title><!-- © James Kanjo 2009 --></head><body><scripttype="text/javascript">
 var newCSS = document.createElement('link');
 newCSS.rel = 'stylesheet';
 
 var css_params = /^#(#[^#]*)#.*$/;
 var css = css_params.exec(unescape(parent.parent.location.hash));
 if (css) {
 newCSS.href = 'data:text/css,' + '@import url("' + css[1].substring(1) + '");';
 }
 document.getElementsByTagName("head")[0].appendChild(newCSS);
 </script><scripttype="text/javascript"><!--
 /* Remove duplicate elements from array function taken from:
 http://www.martienus.com/code/javascript-remove-duplicates-from-array.html
 */
 function unique(a) {
 var r = new Array();
 o:for(var i = 0, n = a.length; i < n; i++) {
 for(var x = 0, y = r.length; x < y; x++) {
 if(r[x]==a[i]) continue o;
 }
 r[r.length] = a[i];
 }
 return r;
 }
 //-->
 
 var params = /^##?[^#]*?(#.*)$/;
 var string_items = params.exec(unescape(window.location.hash))[1];
 
 var items = new Array();
 var tmp_count = 0;
 
 while (0<=string_items.search(/#/)) {
 string_items = string_items.substring(string_items.search(/#/)+1);
 items[tmp_count] = string_items.substring(string_items.search(/#/)+1);
 if (0<=string_items.search(/#/))
 items[tmp_count] = string_items.substring(0,string_items.search(/#/));
 tmp_count = tmp_count+1;
 }
 
 items = unique(items);
 for (tmp_count=0;tmp_count<=items.length-1;tmp_count++) {
 document.write('<spanclass="unique-item">' + items[tmp_count] + '</span><br/>');
 }
 </script></body></html>

Code

Use the ListPages module to compile the list that may have duplicate results:

[[module ListPages perPage="250" limit="250" separate="false" appendLine="[[include :snippets:code:_rdr |no-results=Sorry! There appears to be no results matching your specified criteria...]]"]]
[[embed]]<iframe frameborder="0" scrolling="auto" style="width: 100%; height: 300px;" src="http://snippets.wdfiles.com/local--code/code:remove-duplicate-results[!--
--]#ITEM[!--
[[/module]]

If you would like to use your own custom CSS for this module, just prepend ##CSS-URL to the [!----] code, like so:

[[module ListPages perPage="250" limit="250" separate="false" appendLine="[[include :snippets:code:_rdr |no-results=Sorry! There appears to be no results matching your specified criteria...]]"]]

[[embed]]<iframe frameborder="0" scrolling="auto" style="width: 100%; height: 300px;" src="http://snippets.wdfiles.com/local--code/code:remove-duplicate-results##CSS-URL[!--

--]#ITEM[!--

[[/module]]

The CSS class used to control the items in the list is .unique-item

In action

This code would be useful if you want to list the most active users over the past 24 hours:

**Currently Active Users:**
[[module ListPages category="*" order="updated_at desc" date="last 1 day" perPage="250" limit="250" separate="false" appendLine="[[include :snippets:code:_rdr |no-results=There appears to be no active users over the past 24 hours...]]"]]
[[embed]]<iframe frameborder="0" scrolling="auto" style="width: 100%; height: 125px;" src="http://snippets.wdfiles.com/local--code/code:remove-duplicate-results[!--
--]#%%created_by%%[!--
[[/module]]

Currently Active Users:

There appears to be no active users over the past 24 hours…
[フレーム]


Thanks to tsangk for this great snippet: conditional-blocks


text above inserted with:

[[include :snippets:if START |unique=1|type=equal|var1=%%name%%|var2=conditional-blocks]]
**##red|Thanks to tsangk for this great snippet:##** [[[code:conditional-blocks]]]
[[include :snippets:if END]]



Other snippets posted by James Kanjo


Rate this solution

If you think this solution is useful — rate it up!

rating: +5
gerdami gerdami 27 Oct 2009 07:22

Well done, James.
Now it would be great if you could count the contributions per user and append (nn) to username, with a new class .count-item, for {display:none;} if not wanted.

by gerdami gerdami , 27 Oct 2009 07:22
page revision: 12, last edited: 16 Feb 2012 01:39
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License
Click here to edit contents of this page.
Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.
Append content without editing the whole page source.
Check out how this page has evolved in the past.
If you want to discuss contents of this page - this is the easiest way to do it.
View and manage file attachments for this page.
A few useful tools to manage this Site.
Change the name (also URL address, possibly the category) of the page.
View wiki source for this page without editing.
View/set parent page (used for creating breadcrumbs and structured layout).

AltStyle によって変換されたページ (->オリジナル) /