Fork me on GitHub
Please upgrade to 2.1.x here. The 2.0 branch is no longer being updated.
Critical: Update to 2.1.8, released 15 Jan.

How to show last 20 topics on other webpages

edited November 2011 in Vanilla 2.0 Help
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.

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 = '';

    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>';

    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.


Sign In or Register to comment.