Go Back   vBulletin Setup > vBulletinSetup Information > Making Money Marketing vBulletin > vBulletin Programming & Coding

Why not Register and remove some of the ads from vBulletin Setup
Post New Thread  Reply



#1   02-01-2007, 09:00 PM
Send a message via AIM to Brandon Send a message via MSN to Brandon Send a message via Yahoo to Brandon Brandon is a glorious beacon of lightBrandon is a glorious beacon of lightBrandon is a glorious beacon of lightBrandon is a glorious beacon of light Join Date: Jul 2006 Posts: 9,243 Location: Topeka, KS
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; 02-07-2008 at 07:12 PM.
Quote   |  



#2   02-11-2008, 07:52 AM
otis will become famous soon enough Join Date: Aug 2007 Posts: 17
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; 02-11-2008 at 01:24 PM. Reason: pls use the code tag
Quote   |  



#3   02-11-2008, 08:33 AM
otis will become famous soon enough Join Date: Aug 2007 Posts: 17
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
Quote   |  



#4   02-12-2008, 01:04 PM
otis will become famous soon enough Join Date: Aug 2007 Posts: 17
Re: Display Content in a Random Order - XHTML Valid Method


anyone?
Quote   |  



#5   02-12-2008, 07:31 PM
Send a message via AIM to Brandon Send a message via MSN to Brandon Send a message via Yahoo to Brandon Brandon is a glorious beacon of lightBrandon is a glorious beacon of lightBrandon is a glorious beacon of lightBrandon is a glorious beacon of light Join Date: Jul 2006 Posts: 9,243 Location: Topeka, KS
Re: Display Content in a Random Order - XHTML Valid Method


I haven't messed with this in a while, sorry
--------------------
Brandon Sheley / vBulletin Setup Staff
Check out our Newsletter for the latest vB and SEO news.
Are you looking for vBulletin work to be done on your forums ?
Would you like to Help Support vBulletin Setup.
Reply to the Welcome PM for Full Access to the Forums.. Thanks

Please do not PM me for support, that's what the forums are for.
Have you heard about Crowdgather?
Find it on Forums
Check out this cool page - Bar Code Signatures
Quote   |  



#6   02-12-2008, 09:47 PM
Michael Biddle is just really niceMichael Biddle is just really nice Join Date: Aug 2006 Posts: 1,514 Location: Anaheim, CA
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>
--------------------
Do NOT PM me for Support!
Michael Biddle / vBulletin Setup Staff
Check out our Newsletter for the latest vB and SEO news.
Are you looking for vBulletin work to be done on your forums ?
Would you like to Help Support vBulletin Setup.
Quote   |  



#7   02-15-2008, 06:45 AM
otis will become famous soon enough Join Date: Aug 2007 Posts: 17


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 07:24 AM. Reason: merge double post
Quote   |  
Post New Thread  Reply
vBulletin Setup > vBulletinSetup Information > Making Money Marketing vBulletin > vBulletin Programming & Coding


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
ICO-Content popowich vBulletin SEO Tips and SEO Questions 6 04-26-2008 08:21 AM
Websites to be answerable for content in India Yogesh Sarkar General Discussion 5 04-22-2008 05:48 PM
$vbsettings Display Order Sgt. D. Pilla vBulletin Questions 0 09-20-2007 07:05 AM
Posting Content in blog or forum brandondrury Blogging Forum 4 08-02-2007 06:20 PM
Free Website Content - Etiquette Brandon Website Marketing Articles 0 08-16-2006 09:56 PM


All times are GMT -6. The time now is 09:23 AM.

vBulletin Setup, vBulletin Setup Forums, vBulletin Services, vBulletin Blogs, vBulletin SEO, vBulletin Questions, vBulletin Skins, Styles, Templates
vBulletin Hacks / Modifications, vBulletin Monetization, Blogs, vBulletin Link Directory,Quality Link Directory