Results 1 to 5 of 5

Thread: Random/Alphabetical Content Order?

  1. #1
    Join Date
    Aug 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Random/Alphabetical Content Order?

    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.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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 for more information.


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

    Code:
    <script type="text/javascript">
    
    //randomize order of contents with DIV class="group1"
    randomizeContent("group1")
    
    </script>
    Make it like so:

    Code:
    <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:

    Code:
    <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:

    Code:
    <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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.
    Last edited by Ynot; 08-28-2012 at 10:34 PM.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Ooops, that should have been:

    Code:
    <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>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Aug 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks John, That works perfectly now. Really appreciate your time and effort in helping me with this.

Bookmarks

Posting Permissions

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