+ Reply to Thread
Results 1 to 2 of 2

Thread: Display listings in a random order.

  1. #1

    Display listings in a random order.

    It's possible to get your listings display in a random order rather than the default using the following script changes. I've tested this in IE8, Chrome and Safari but obviously offer no guarantees.

    It will display in a random order your Priority Entries and then your Normal Entries. As the script has to be included in the t!wdview.html template a problem crops up if you do not have at least one of each listing type. I've overcome that with a quick javascript "hide error message" script as well.

    First of all you need 2 javascript files loaded externally. Content is identical in both, call one entryHigh.js and the other entryNorm.js. Upload both files to your web server in same location as all other files.

    Here's the code:

    // JavaScript Document
    /***********************************************
    * Random Content Order script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
    ***********************************************/

    function randomizeContent(classname){
    var contents=randomizeContent.collectElementbyClass(cl assname)
    contents.text.sort(function() {return 0.5 - Math.random();})
    var tbodyref=contents.ref[0].tagName=="TR"? contents.ref[0].parentNode : new Object()
    for (var i=0; i<contents.ref.length; i++){
    if (tbodyref.moveRow) //if IE
    tbodyref.moveRow(0, Math.round(Math.random()*(tbodyref.rows.length-1)))
    else
    contents.ref[i].innerHTML=contents.text[i]
    contents.ref[i].style.visibility="visible"
    }
    }

    randomizeContent.collectElementbyClass=function(cl assname){ //return two arrays containing elements with specified classname, plus their innerHTML content
    var classnameRE=new RegExp("(^|\\s+)"+classname+"($|\\s+)", "i") //regular expression to screen for classname within element
    var contentobj=new Object()
    contentobj.ref=new Array() //array containing references to the participating contents
    contentobj.text=new Array() //array containing participating contents' contents (innerHTML property)
    var alltags=document.all? document.all : document.getElementsByTagName("*")
    for (var i=0; i<alltags.length; i++){
    if (typeof alltags[i].className=="string" && alltags[i].className.search(classnameRE)!=-1){
    contentobj.ref[contentobj.ref.length]=alltags[i]
    contentobj.text[contentobj.text.length]=alltags[i].innerHTML
    }
    }
    return contentobj
    }

    Next we need to add these bits to the t!wdview.html page.


    In the head section add just below the grvalidator line (about line22)

    <script type="text/javascript" src="entryHigh.js"></script>
    <script type="text/javascript" src="entryNorm.js"></script>
    <script type="text/javascript">

    function noError(){return true;}
    window.onerror = noError;

    </script>
    <style type="text/css">
    .entryHigh{
    visibility: hidden;
    }
    .entryNorm{
    visibility: hidden;
    }
    </style>

    Then look for

    <!--/entryList-->
    {$listings}


    Immediately below that add the following

    <script type="text/javascript">
    randomizeContent("entryHigh")
    </script>


    <script type="text/javascript">
    randomizeContent("entryNorm")
    </script>


    Save and upload. If you only want to display one type randomly just delete the other from all places. You must leave the error code checker script in if any page does not have the type of listing you want to randomise.

    So far this has worked well but I only have listings on one page. When the script starts adding additional pages (set here in wdcfg.php define('WDENTPPAGE', 20); not yet sure how will react.

    Hope you like it.

    Mike

  2. #2
    The above modification should work alright; it will shuffle all listings that are on the page normally in random order, and if you have more than one page in a category, for example 30 listings and your number of listings per page (WDENTPPAGE) is set to 20, then it will just shuffle the first 20 on the first page and then the other 10 on the next page.
    Normally you would have all your priority listings on the first page, where they will stay but in a random order.

    You can also order your listings per date submitted rather than alphabetically, and/or per rank or not (Priority - Standard). This ordering would then be applied before any shuffling.

    More info here:
    http://www.goldroo.com/software/settings/#wdnorankorder
    http://www.goldroo.com/software/sett...wdlistingorder
    Last edited by john; 12th March 2011 at 09:18 PM.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts