Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

recent discussions-How to

edited November 2007 in Vanilla 1.0 Help
hi everyone! new to vanilla! i have a question. is there a way to put a block of the recent discusions into my home page?which is wordpress. like http://www.cssbeauty.com/ has at the bottom and other sites.and how. thanks a lot
«1

Comments

  • NickENickE New
    edited September 2006
    If you didn't mind messing a little with php, you could include() the following from your page, then call GetRecentDiscussions() where you wanted the latest discussions to go:
    <?php
    
    if(!defined('VANILLA_DIR')) define('VANILLA_DIR', './');
    
    include(VANILLA_DIR.'appg/settings.php');
    include(VANILLA_DIR.'appg/init_ajax.php');
    
    function GetRecentDiscussions($Limit = 10)
    {
    	$DiscFields = &$GLOBALS['DatabaseColumns']['Discussion'];
    	$Data = $GLOBALS['Context']->Database->Execute(
    		'select 
    			t.'.$DiscFields['DiscussionID'].', 
    			t.'.$DiscFields['Name'].' 
    		from '.$GLOBALS['Configuration']['DATABASE_TABLE_PREFIX'].
    			$GLOBALS['DatabaseTables']['Discussion'].' t 
    		where 
    			t.'.$DiscFields['Active'].' = \'1\' and 
    			(
    				t.'.$DiscFields['WhisperUserID'].' = \'0\' or 
    				t.'.$DiscFields['WhisperUserID'].' = 0 or 
    				t.'.$DiscFields['WhisperUserID'].' is null
    			)
    		order by t.'.$DiscFields['DateLastActive'].' desc
    		limit 0, '.$Limit.';', '', '', '', 0);
    	
    	echo('<ul id="LatestVanillaDiscussions">');
    	if(!$Data)
    	{
    		echo('<li>[An error occured while retrieving latest discussions]</li></ul>');
    		return;
    	}
    	
    	while( $Row = $GLOBALS['Context']->Database->GetRow($Data) )
    		echo('<li><a href="'.VANILLA_DIR.'comments.php?DiscussionID='.
    			$Row['DiscussionID'].'">'.FormatStringForDisplay($Row['Name']).'</a></li>
    	');
    	
    	echo('</ul>');
    }
    
    ?>
    For example, if you put that in a file called 'getdiscussions.php' in your main directory, and your page was in the same dir, then you could use the following snippet to include it:
    <?php
    define('VANILLA_DIR', '[your forum subfolder]/');
    include('getdiscussions.php');
    ?>
    [your page]
    <?php
    GetRecentDiscussions();
    ?>
  • thanks for the reply. ill try that
  • i had this Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/adsforhe/public_html/wp-content/themes/hemingway/header.php:5) in /home/adsforhe/public_html/test/library/People/People.Class.Authenticator.php on line 93
  • NickENickE New
    edited September 2006
    Ah, right, didn't count on that.

    Updated the first post, try it now, and make sure it's include()ed before any of the page is outputted.
  • i have the same warning! i dont know. im sure im doing something wrong!
  • I'm sure one could make this into a wordpress plugin...
  • that would be great! is it possible to be done with RSS?
  • NickENickE New
    edited September 2006
    Hmmm, there dosn't appear to be any way to add items to the bottom of the sidebar via an extension, so I'm afraid you'd probably be better of modifying a few files. This worked for me on wordpress 1.5.1.2:

    Open up wp-blog-header.php and find this conditional block:
     } else if ( empty($feed) ) {
    	@header('X-Pingback: '. get_bloginfo('pingback_url'));
    	@header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
    }
    Then insert somewhere within that conditional the include() code (assuming you've called the file getdiscussions.php):
    	define('VANILLA_DIR', '[vanilla install, relative to wp dir]');
    	include('getdiscussions.php');
    Then go into wp-content/themes/[your theme]/sidebar.php and add in the unorded list, wherever you feel the discussion list should go:<li>Lastest Discussions<?php GetRecentDiscussions(); ?></li>
  • I have been trying to do this also, so thanks for the instructions. However, i use WP 2.0.4 and Vanilla 1.0.1. So, that wp-blog-header is way different than the wp-blog-header you gave instructions to. Here is the WP 2.0.4 wp-blog-header: <?php if (! isset($wp_did_header)): if ( !file_exists( dirname(__FILE__) . '/wp-config.php') ) { if ( strstr( $_SERVER['PHP_SELF'], 'wp-admin') ) $path = ''; else $path = 'wp-admin/'; die("There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='http://wordpress.org/docs/faq/#wp-config'>We got it</a>. You can <a href='{$path}setup-config.php'>create a <code>wp-config.php</code> file through a web interface</a>, but this doesn't work for all server setups. The safest way is to manually create the file."); } $wp_did_header = true; require_once( dirname(__FILE__) . '/wp-config.php'); wp(); gzip_compression(); require_once(ABSPATH . WPINC . '/template-loader.php'); endif; ?> Where in this 2.0.4 version of wp-blog-header would i put this: define('VANILLA_DIR', '[vanilla install, relative to wp dir]'); include('getdiscussions.php'); Thanks for any help. Chris
  • NickENickE New
    edited September 2006
    My goodness, that is different.

    But, assuming you just want the list on the front page, add this right after the call to gzip_compression() in wp_blog_header.php:
    if(is_home() || is_page())
    {
    	define('VANILLA_DIR', '[vanilla_dir]');
    	include('getdiscussions.php');
    }
    Then you'd want to modify what you put in the theme file, changing it to this:
      <?php
       if(function_exists('GetRecentDiscussions'))
       {
        echo('<li><h2>Latest Discussions</h2>');
        GetRecentDiscussions();
        echo('</li>');
       }
      ?>
    Sorry for all the confusion.
  • No problem, i appreciated all the help. So, when i put that in the wp-blog-header (under the gzip compression call), when i try to call my page, it just sits there "waiting for www.mytimewithgod.net". Then i take if(is_home() || is_page()) { define('VANILLA_DIR', '[/forum]'); include('getdiscussions.php'); } out (of wp-blog-header.php), no problems getting to my page. I wonder if the Vanilla dir is correct/correct syntax? I have tried ./forum and /forum. The structure is www.mytimewithgod.net is WP dir and Vanilla dir is www.mytimewithgod.net/forum (i have getdiscussions.php inside the /forum dir). Thanks again for all your help!! Chris
  • edited September 2006
    OK, so when i make the Vanilla_dir (define('VANILLA_DIR', '[http://www.mytimewithgod.net/forum]');), i get this error: Warning: main(getdiscussions.php) [function.main]: failed to open stream: No such file or directory in /srv/www/htdocs/wp-blog-header.php on line 19 Warning: main() [function.include]: Failed opening 'getdiscussions.php' for inclusion (include_path='.:') in /srv/www/htdocs/wp-blog-header.php on line 19 getdiscussions.php is in the /forum folder with correct permissions (or permissions of other files like extensions.php). EDIT--Samething when i just use forum ((define('VANILLA_DIR', '[forum]');
  • ithcyithcy New
    edited September 2006
    the script that's generating the "not found" error, wp-blog-header.php, is in /
    getdiscussions.php is in /forum
    your include_path is "." which equates to "/" for the wp-blog-header script.

    so no, it's not going to find it because it's not looking in /forum for it :)

    either change your include path to have ":/forum" in it, or change the script to include forum/getdiscussions.php.
  • Sorry but i don't understand. I am new to Vanilla and php for that matter. How do i change your include path to have ":/forum" in it, or change the script to include forum/getdiscussions.php. do i change the wp-blog-header.php file or what? Confused
  • in wp-blog-header.php, where it says

    include('getdiscussions.php');

    change that to

    include('forum/getdiscussions.php');

    and see where that gets you.
  • Here it is: Warning: main([vanilla_dir]appg/settings.php) [function.main]: failed to open stream: No such file or directory in /srv/www/htdocs/forum/getdiscussions.php on line 5 Warning: main() [function.include]: Failed opening '[vanilla_dir]appg/settings.php' for inclusion (include_path='.:') in /srv/www/htdocs/forum/getdiscussions.php on line 5 Warning: main([vanilla_dir]appg/init_ajax.php) [function.main]: failed to open stream: No such file or directory in /srv/www/htdocs/forum/getdiscussions.php on line 6 Warning: main() [function.include]: Failed opening '[vanilla_dir]appg/init_ajax.php' for inclusion (include_path='.:') in /srv/www/htdocs/forum/getdiscussions.php on line 6
  • ithcyithcy New
    edited September 2006
    heh

    when SirNot said
    define('VANILLA_DIR', '[vanilla_dir]');
    he didn't mean it literally. at least i hope not. he meant for you to replace [vanilla_dir] with your actual vanilla dir. like so:
    define('VANILLA_DIR', '/forum/');
  • Umm, yea, i am aware of that and you can see, up 7 posts, that i, in fact, have that in the code. Still get the error: Warning: main([/forum/]appg/settings.php) [function.main]: failed to open stream: No such file or directory in /srv/www/htdocs/forum/getdiscussions.php on line 5 Warning: main() [function.include]: Failed opening '[/forum/]appg/settings.php' for inclusion (include_path='.:') in /srv/www/htdocs/forum/getdiscussions.php on line 5 Warning: main([/forum/]appg/init_ajax.php) [function.main]: failed to open stream: No such file or directory in /srv/www/htdocs/forum/getdiscussions.php on line 6 Warning: main() [function.include]: Failed opening '[/forum/]appg/init_ajax.php' for inclusion (include_path='.:') in /srv/www/htdocs/forum/getdiscussions.php on line 6
  • you've got to take out the brackets.
    like i said, define('VANILLA_DIR', '/forum/');
    not define('VANILLA_DIR', '[/forum/]');
  • Oh, my mistake. I still get the same error with this code in my wp-blog-header.php file: if(is_home() || is_page()) { define('VANILLA_DIR', '/forum/'); include('forum/getdiscussions.php'); } I also tried this code: if(is_home() || is_page()) { define('VANILLA_DIR', '/forum/'); include('/forum/getdiscussions.php'); } Not sure what i am doing wrong but i can not get this to work. Thanks guys for all your help, so far!
This discussion has been closed.