Welcome to our forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Forum Statistics

  • Forum Members:
  • Total Threads:
  • Total Posts: 46
There are 1 users currently browsing forums.
Articles, Tutorials, and Guides Here is a collection of tutorials. You may submit tutorials and read them as you please.

Reply
  #1  
Old 09-12-2006
Mau Mau is offline
A friend
 
Join Date: Jun 2005
Location: California, USA
Age: 19
Posts: 2,956
Rep Power: 7
Mau is on a distinguished road
How to Create the Ajax Sidebar with Recent Posts or Threads in vBulletin

I've had a few people ask me how I created the ajax sidebar on our newer styles. Here's how:

I) Setting up the Feed
1) First, you need the improved external.php file from vBulletin.org. The link is here: http://www.vbulletin.org/forum/showt...t=fps_external

2) This new external file lacks some of the documented features, and the feature we need is the latest posts (not latest threads). The attached file resolves that and may only be used if you have a valid vBulletin license. The reason we may not use the built-in one is because it does not have support for permissions and will therefore treat every user as a guest. Credit for fps_external.php goes to the original authors; my revision was trivial.

3) Upload fps_external.php into your forum directory.

II) Setting up the Ajax
1) Our threads are going to appear in an unordered list. So, let's setup our default list:
HTML Code:
  <ul id="latestthreads">
   <li>Please wait while the feed updates.</li>
  </ul>
We have to throw in the please wait to make our page validate and also to notify our users that we're fetching the feed.

2) You then need some JavaScript. I'm not going to document this as it's pretty self-explanatory:
Code:
/*
* Ajax sidebar for vBulletin.
* Depends: hacked fps_external.php
* Created for: www.youngcoders.com
*/


function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function updateSidebarResponse() {
    if(http.readyState == 4){
        var length = document.getElementById('latestthreads').getElementsByTagName('li').length;
        for (var y = 0; y < length; y++)
        { 
                document.getElementById('latestthreads').removeChild( document.getElementById('latestthreads').getElementsByTagName('li')[0] );
        }
        
        
        var response = http.responseXML.getElementsByTagName('source')[0].getElementsByTagName('thread');
        var length = response.length;
        for (var x = 0; x < length; x++)
        {
                var id = response[x].getAttribute('id');
                var title = response[x].getElementsByTagName('title')[0].childNodes[0].nodeValue;
                var author = response[x].getElementsByTagName('author')[0].childNodes[0].nodeValue;
                var when = response[x].getElementsByTagName('time')[0].childNodes[0].nodeValue;

                var top = document.createElement('div');
                var bottom = document.createElement('div');

                var option = document.createElement('li');
                var link = document.createElement('a');
                link.href = 'thread' + id + '->newpost';
                link.appendChild(document.createTextNode(title));
                var by = document.createElement('small');
                by.appendChild(document.createTextNode(' by ' + author + ' at ' + when));

                option.appendChild(link);
                option.appendChild(by);

                document.getElementById('latestthreads').appendChild(option);
        }
    }
}

function updateSidebar() {
    http.open('get', 'fps_external.php?type=xml&qty=20&items=active');
    http.onreadystatechange = updateSidebarResponse;
    http.send(null);
}


updateSidebar();
The above code will fetch the sidebar just once. To make it update, you must have it run through intervals:
Code:
setInterval('updateSidebar()', 60000 * 1); // Update every minute
setInterval('updateSidebar()', 60000 * 3); // Update every 3 minutes
Terms of Use: For each site you deploy this on, you must tell one friend about YoungCoders.com
Attached Files
File Type: txt fps_external.php.txt (26.6 KB, 80 views)
Reply With Quote
  #2  
Old 09-12-2006
A "Mature" Pre-Teenager!
 
Join Date: Sep 2005
Posts: 128
Rep Power: 5
blindchild02 is on a distinguished road
Re: How to create the Ajax Sidebar in vBulletin

hmm.. could you explain the javascript part more... do I put it in a new file??
im sorry I dont know much about that stuff
Reply With Quote
  #3  
Old 09-12-2006
Forum Administrator
 
Join Date: Mar 2006
Location: Toronto, Ontario
Posts: 2,396
Rep Power: 7
Nick Presta is on a distinguished road
Re: How to create the Ajax Sidebar in vBulletin

Traditionally, you would put the JavaScript into a file and then link it like so (in the head section):
Code:
<script type="text/javascript" src="/path/to/javascript.js"></script>
The setInterval() function will call the various functions at the specified times.
Reply With Quote
  #4  
Old 09-12-2006
A "Mature" Pre-Teenager!
 
Join Date: Sep 2005
Posts: 128
Rep Power: 5
blindchild02 is on a distinguished road
Re: How to create the Ajax Sidebar in vBulletin

and the setinterval() function goes into the javascript file aswell?
Reply With Quote
  #5  
Old 09-12-2006
Forum Administrator
 
Join Date: Mar 2006
Location: Toronto, Ontario
Posts: 2,396
Rep Power: 7
Nick Presta is on a distinguished road
Re: How to create the Ajax Sidebar in vBulletin

Yes, at the bottom.

I'm not a whiz with JavaScript so I am unsure if you need to wrap the two setInterval() functions in this:
Code:
window.onload = function() {
// set interval functions
}
Reply With Quote
  #6  
Old 09-12-2006
A "Mature" Pre-Teenager!
 
Join Date: Sep 2005
Posts: 128
Rep Power: 5
blindchild02 is on a distinguished road
Re: How to create the Ajax Sidebar in vBulletin

heh.. could anyone simplify this by just attaching the javascript file, and then giving the code in which I need to implement into the template?
Reply With Quote
  #7  
Old 09-12-2006
Mau Mau is offline
A friend
 
Join Date: Jun 2005
Location: California, USA
Age: 19
Posts: 2,956
Rep Power: 7
Mau is on a distinguished road
Re: How to create the Ajax Sidebar in vBulletin

See attached. You have to put this after your <ul>...</ul>, if you use this file.
Attached Files
File Type: txt js.txt (2.2 KB, 62 views)
Reply With Quote
  #8  
Old 09-12-2006
A "Mature" Pre-Teenager!
 
Join Date: Sep 2005
Posts: 128
Rep Power: 5
blindchild02 is on a distinguished road
Re: How to create the Ajax Sidebar in vBulletin

ok, tried that, and it just showed all the text.. do I need a <style> tag or something?

<- not a programmer... designer lol
Reply With Quote
  #9  
Old 09-12-2006
Mau Mau is offline
A friend
 
Join Date: Jun 2005
Location: California, USA
Age: 19
Posts: 2,956
Rep Power: 7
Mau is on a distinguished road
Re: How to create the Ajax Sidebar in vBulletin

Yes, you must style it using CSS. It'll just generate your generic sidebar, but you are up to style it.
Reply With Quote
  #10  
Old 09-13-2006
Toddler
 
Join Date: Sep 2006
Posts: 5
Rep Power: 0
SilverSiR is on a distinguished road
Re: How to Create the Ajax Sidebar in vBulletin

Yeah this is a very awesome script. I just have issues with the link.

If you can visit my site at http://www.newurbanite.com, you can see that the links don't take you to the thread.

I have no idea how to fix it, tried looking at the script myself but couldn't figure it out. Also is there a way to get search friendly engine links?
Reply With Quote


Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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
Latest threads actually latest posts? Aros Suggestions 6 09-20-2005 12:25 PM