PDA

View Full Version : Random/Alphabetical Content Order?



Ynot
08-27-2012, 09:53 PM
Hi - Iím using the Random Content Order Script and want to also be able to offer the choice of showing the content alphabetically. At present I code the content in alphabetical order and show it on another page that doesnít include the script. So one page is random and the other is alphabetical. Links take you back and forth between pages. I would like to do this on the same page essentially by turning the Random Content Order Script off and on within the same page. Is this possible? Hope that makes sense.

jscheuer1
08-28-2012, 01:43 AM
In the future, please post about Dynamic Drive Scripts in the Dynamic Drive Scripts Help section here where I've moved this thread, and:

Warning: Please include a link to the DD script(s) in question in your post. See this post (http://www.dynamicdrive.com/forums/showpost.php?p=7) for more information.

At the bottom of the page, where you have something like:


<script type="text/javascript">

//randomize order of contents with DIV class="group1"
randomizeContent("group1")

</script>

Make it like so:


<script type="text/javascript">
(function(){
function getQval(n) {
if(typeof n !== 'string'){
return null;
}
var r = new RegExp('[?&;]' + n + '=([^&;#]*)'), m = location.search;
return (m = r.exec(m))? unescape(m[1]) : null;
}
if(getQval('orig') === 'true'){
//randomize order of contents with DIV class="group1"
randomizeContent("group1")
}
})();
</script>

Now you can have a link on the page to the page - let's say the name of the page is content.html, then like so:


<a href="content.html?orig=true">See Content in its Original Order</a>

Any other link to the page will show the random content again, like:


<a href="content.html">See Content in Random Order</a>

However, once ?orig=true is in the address bar, refreshing the page will not randomize.

Ynot
08-28-2012, 09:39 PM
Very sorry - <pathetic excuse>my first post in this forum</pathetic excuse>

Thanks for your code but I get this error message - Expected '}'

ETA - Fixed above problem (my error). The script works fine but does the opposite of what I want. When you first visit the page it shows in alphabetical order (order as coded) and when you click the "See Content in its Original Order" link it shows in random order. I want random to show first then alphabetical on clicking the link.

jscheuer1
08-29-2012, 05:28 AM
Ooops, that should have been:


<script type="text/javascript">
(function(){
function getQval(n) {
if(typeof n !== 'string'){
return null;
}
var r = new RegExp('[?&;]' + n + '=([^&;#]*)'), m = location.search;
return (m = r.exec(m))? unescape(m[1]) : null;
}
if(getQval('orig') !== 'true'){
//randomize order of contents with DIV class="group1"
randomizeContent("group1");
}
})();
</script>

Ynot
08-30-2012, 12:56 AM
Thanks John, That works perfectly now. Really appreciate your time and effort in helping me with this.