Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Embed Only Category Panel

edited March 2011 in Vanilla 2.0 - 2.8
Hi,
I need to display my vanilla forum's categories panel on another website. I can't use the plugin because it embeds the entire forum - I want just the categories box.

The idea is to display the category panel in a sidebar on my website, and when visitors click on one of the category links, they'll be taken to the forum installation.

Any ideas on how this can be done?

Comments

  • Options
    Bump! really need help here...
  • Options
    This isn't exactly what you asked for, but here is what I use to get just the recent discussions displayed on my main site. Perhaps this is sufficient or could be extended. I snagged this from the Wordpress Vanilla Forum Plugin. There is a section marked where you will need to hard code your configuration (i.e. url, number to display, CSS tags, etc.). There are also several tag id and class elements that will need to be setup in your style sheet to gussy it up. Hope this helps.

    <?php function vf_get_value($Key, &$Collection, $Default = FALSE) { $Result = $Default; if(is_array($Collection) && array_key_exists($Key, $Collection)) { $Result = $Collection[$Key]; } elseif(is_object($Collection) && property_exists($Collection, $Key)) { $Result = $Collection->$Key; } return $Result; } function vf_rest($Url) { try { $C = curl_init(); curl_setopt($C, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($C, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($C, CURLOPT_URL, $Url); $Contents = curl_exec($C); if ($Contents === FALSE) $Contents = curl_error($C); $Info = curl_getinfo($C); if (strpos(vf_get_value('content_type', $Info, ''), '/javascript') !== FALSE) { $Result = json_decode($Contents, TRUE); if (is_array($Result) && isset($Result['Exception']) && isset($Result['Code'])) { curl_close($C); throw new Exception($Result['Exception'], $Result['Code']); } } else { $Result = $Contents; } curl_close($C); return $Result; } catch (Exception $ex) { return $ex; } } function vf_combine_paths($paths, $delimiter = DS) { if (is_array($paths)) { $munged_path = implode($delimiter, $paths); $munged_path = str_replace(array($delimiter.$delimiter.$delimiter, $delimiter.$delimiter), array($delimiter, $delimiter), $munged_path); return str_replace(array('http:/', 'https:/'), array('http://', 'https://'), $munged_path); } else { return $paths; } } function vf_format_url($string) { $string = strip_tags(html_entity_decode($string, ENT_COMPAT, 'UTF-8')); $string = preg_replace('`([^\PP.\-_])`u', '', $string); // get rid of punctuation $string = preg_replace('`([^\PS+])`u', '', $string); // get rid of symbols $string = preg_replace('`[\s\-/+]+`u', '-', $string); // replace certain characters with dashes $string = rawurlencode(strtolower($string)); return $string; } function vf_recent_discussions() { /* ********************************************/ /* ************ Configure These **************/ /* ********************************************/ $title = 'Recent Discussions'; $categoryid = 0; $count = 5; $before_widget = '<div id="vf-widget-discussions" class="your_side_panel vf_widget_discussions">'; $before_title = '<h3>'; $after_title = '</h3>'; $after_widget = '</div>'; $url = 'http://www.domain.com/forum/'; $link_url = 'http://www.domain.com/forum/'; /* ********************************************/ $resturl = array($url, '?p=discussions.json'); if ($categoryid > 0) $resturl = array($url, '?p=categories/'.$categoryid.'.json'); $DataName = $categoryid > 0 ? 'DiscussionData' : 'Discussions'; // Retrieve the latest discussions from the Vanilla API $resturl = vf_combine_paths($resturl, '/'); $data = json_decode(vf_rest($resturl)); if (!is_object($data)) return; // These lines generate our output. Widgets can be very complex // but as you can see here, they can also be very, very simple. echo $before_widget . $before_title . $title . $after_title; echo '<ul>'; $i = 0; foreach ($data->$DataName as $Discussion) { $i++; if ($i > $count) break; echo '<li><a href="'.vf_combine_paths(array($link_url, 'discussion/'.$Discussion->DiscussionID.'/'.vf_format_url($Discussion->Name)), '/').'">'.$Discussion->Name.'</a></li>'; } echo '</ul>'; echo $after_widget; } ?> <div id="sidebar"> <ul class="sidebar_list"> <li> <?php vf_recent_discussions(); ?> </li> </div>



  • Options
    Thanks! I think this might help! I'll look into it.
  • Options

    Hi, Thanks, I know this thread is going a long way back but I have tried everything to display the submissions of one category into another website. This is the first one that worked without any problems, except like you mention it displays all categories. If you are able to respond after 2 years I would appreciate very much if you can guide me to only display one category on another website. Where can I alter your code to do this. I am not a programmer or experienced php person.
    Thanks in advance

  • Options
    hgtonighthgtonight ∞ · New Moderator

    @javo You should be able to specify a category id to get just a specific category.

    Find the line that looks like this:

    /* ********************************************/
    /* ************ Configure These **************/
    /* ********************************************/
    $title = 'Recent Discussions';
    $categoryid = 0;
    $count = 5;
    

    The only trick is to figure out what ID the category you want is. Navigate to http://www.yoursite.com/vanilla/settings/managecategories. Then view the page source (right click on the background, select 'view source' or similar). The you need to search for 'editcategory/'. The number behind that is the category id. You will have to read the surrounding data to know what category it corresponds to.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Sign In or Register to comment.