Go Back   vBulletin Setup > vBulletinSetup Information > Community Forum Management > Make Money with vBulletin

Reply 
 
LinkBack Thread Tools Display Modes
Old 02-01-2007, 07:00 PM   #1
Community Manager
Supporters
vBulletin Owner
vBSetup Mods
 
Brandon Sheley's Avatar
 
Join Date: Jul 2006
Location: Topeka, KS
Posts: 14,115
Blog Entries: 35
Brandon Sheley is a splendid one to beholdBrandon Sheley is a splendid one to beholdBrandon Sheley is a splendid one to beholdBrandon Sheley is a splendid one to beholdBrandon Sheley is a splendid one to beholdBrandon Sheley is a splendid one to behold
Send a message via AIM to Brandon Sheley Send a message via MSN to Brandon Sheley Send a message via Yahoo to Brandon Sheley
Display Content in a Random Order - XHTML Valid Method

This is not just another banner rotator mod.

This will allow you to define an array of content (banners, links, text, whatever), then have them display in a random order with each page refresh.

Copy this code and save it as random.js

Code:
function randomizeContent(classname){

var contents=randomizeContent.collectElementbyClass(classname)

contents.text.sort(function() {return 0.5 - Math.random();})

for (var i=0; i<contents.ref.length; i++){

contents.ref[i].innerHTML=contents.text[i]

contents.ref[i].style.visibility="visible"

}

}



randomizeContent.collectElementbyClass=function(classname){ //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

}
Upload random.js to your clientscript folder.

Copy the follow to your 'Additional CSS' section of your style

Code:
.group1{
visibility: hidden;
}
Add the following code to the bottom of your HEADINCLUDE template

Code:
<script type="text/javascript" src="clientscript/random.js"></script>
Insert your content using <div class=group1> tags. Be sure to include the code below the html

Code:
<div class="group1">
Content 1
</div>

<div class="group1">
Content 2
</div>

<div class="group1">
Content 3
</div>

<div class="group1">
Content 4
</div>

<div class="group1">
Content 5
</div>


<script type="text/javascript">

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

</script>
You can make as many groups as needed, and call this script multiple times. Just be sure to repeat the CSS and div classes using group2, group3, etc...

Last edited by Brandon Sheley; 02-07-2008 at 05:12 PM.
Brandon Sheley is offline   Reply With Quote

Advertisement [Remove Advertisement]

Old 02-11-2008, 05:52 AM   #2
vBulletin Owner
 
Join Date: Aug 2007
Posts: 21
otis will become famous soon enough
Re: Display Content in a Random Order - XHTML Valid Method

will this work for Forum Descriptions also? where do i put this last part of code exactly?

Code:
<div class="group1">
Content 1
</div>

<div class="group1">
Content 2
</div>

<div class="group1">
Content 3
</div>

<div class="group1">
Content 4
</div>

<div class="group1">
Content 5
</div>


<script type="text/javascript">

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

</script>

Last edited by Brandon Sheley; 02-11-2008 at 11:24 AM. Reason: pls use the code tag
otis is offline   Reply With Quote
Old 02-11-2008, 06:33 AM   #3
vBulletin Owner
 
Join Date: Aug 2007
Posts: 21
otis will become famous soon enough
Re: Display Content in a Random Order - XHTML Valid Method

what i want to do is have a random forum description for one specific forum. i'm sure this will do the trick but i'm not sure whether i need a conditional code or not and where to put it exactly
otis is offline   Reply With Quote
Old 02-12-2008, 11:04 AM   #4
vBulletin Owner
 
Join Date: Aug 2007
Posts: 21
otis will become famous soon enough
Re: Display Content in a Random Order - XHTML Valid Method

anyone?
otis is offline   Reply With Quote
Old 02-12-2008, 05:31 PM   #5
Community Manager
Supporters
vBulletin Owner
vBSetup Mods
 
Brandon Sheley's Avatar
 
Join Date: Jul 2006
Location: Topeka, KS
Posts: 14,115
Blog Entries: 35
Brandon Sheley is a splendid one to beholdBrandon Sheley is a splendid one to beholdBrandon Sheley is a splendid one to beholdBrandon Sheley is a splendid one to beholdBrandon Sheley is a splendid one to beholdBrandon Sheley is a splendid one to behold
Send a message via AIM to Brandon Sheley Send a message via MSN to Brandon Sheley Send a message via Yahoo to Brandon Sheley
Re: Display Content in a Random Order - XHTML Valid Method

I haven't messed with this in a while, sorry
__________________
Brandon Sheley / vBulletinSetup Staff
Check the Newsletter & Marketplace for the latest deals.
Looking for a place to Support vBulletinSetup?
Submit your Forum and other Quality Websites.


Brandon Sheley is offline   Reply With Quote
Old 02-12-2008, 07:47 PM   #6
Supporters
vBulletin Owner
 
Michael Biddle's Avatar
 
Join Date: Aug 2006
Location: Anaheim, CA
Posts: 1,657
Michael Biddle is just really niceMichael Biddle is just really niceMichael Biddle is just really nice
Re: Display Content in a Random Order - XHTML Valid Method

Well if you want a random description, that would be in the forumhome_forumbit_level2_post template.

You would need an if statement around w/e you add into the template

Find:

Code:
$forum[description]

Replace with:

Code:
<if condition="$forum['forumid'] == x">
Random Description javascipt code here
<else />
$forum[description]
</if>
__________________
I hate that someone changed my signature.
Michael Biddle is offline   Reply With Quote
Old 02-15-2008, 04:45 AM   #7
vBulletin Owner
 
Join Date: Aug 2007
Posts: 21
otis will become famous soon enough
any chance you can show me an example of this? i'm learning as i go here

i got it nevermind. thanks for the help

Last edited by ARealRedneck; 02-15-2008 at 05:24 AM. Reason: merge double post
otis is offline   Reply With Quote
Reply 
vBulletin Setup > vBulletinSetup Information > Community Forum Management > Make Money with vBulletin

Tags
content, display, method, order, random, valid, xhtml

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Method Not Implemented ... ForYou Troubleshooting vBulletin Problems 4 03-09-2009 04:51 PM
Which article submission method is best for SEO sam123 vBulletin SEO Tips and SEO Questions 1 12-10-2008 05:20 AM
$vbsettings Display Order Sgt. D. Pilla Troubleshooting vBulletin Problems 0 09-20-2007 05:05 AM
Display random image! DeeNice Forum Design, Graphics & Customization 1 11-26-2006 05:19 PM
Valid XHTML 1.0? StuntFactoryX General Discussion 4 11-17-2006 10:27 AM


All times are GMT -8. The time now is 06:45 AM.