Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter
Support for Vanilla Forums Cloud product

In this Discussion

Follow Us


How to show last 20 topics on other webpages

edited November 2011 in Questions
I have already installed Vanilla Forums on my website.
Now , I want to show last 20 topics on my homepage.
I don't know much of API . Just need some working codes.
Tagged:

Best Answer

  • ToddTodd Chief Product Officer Vanilla Staff
    Answer ✓
    I'm going to help you get started with some javascript that we've done for a client.

    Please note that this script uses jQuery so you'll need to include that in your page as well. It is a very common library and should work. You should really know javascript and jQuery a little bit or you'll be flying blind though.
    // Include this script where you want to embed the latest 20 discussions.
    // This script requires jQuery.

    document.write('<div id="vn_discussions_popular"></div>');

    jQuery(document).ready(function($) {
    var url = 'http://yourforumhere.com/discussions.json?page=1-20&callback=?';

    $.ajax({
    url: url,
    dataType: 'json',
    success: function(data) {
    var foo = 'bar';
    var result = '';

    for(i in data.Discussions) {
    d = data.Discussions[i];
    result += '<li><a href="'+d.Url+'">'+d.Name+'</a></li>';
    }

    result = '<ul>'+result+'</ul>';
    $('#vn_discussions_popular').html(result);
    }
    });
    });
    Notes

    1. Notice that the url looks very similar to the url that your browse to when viewing the forum normally. The only difference is that it has a .json?page=1-20&callback=? on the end. This is the API in action and you can call most urls that way.

    2. If you want to figure out what kind of data is returned from the API I recommend getting the excellent JSONView Firefox extension. Once you've installed this you can copy that api url into your browser and have a look at what comes out. If you don't install JSONView you can still look at the url, but you will be prompted to download.
    SteveX

Answers

Sign In or Register to comment.