x
 
Create New Page
 View Previous Changes    ( Last updated by mahalie )

Automatic blog entry to forum entry

So you want one or many of your weblog articles to be automagically populated to your forums, can it be done? Hell yes !!

I will try to make this as generic as possible and is based on the excellent “forum_fill” extension created by Robin Sowell with the base instructions & extension found here. The extension must be placed on your webserver in the folder system>extensions and then in the CP head to CP Home>Admin>Utilities>Extensions Manager and make sure the extension is “enabled”

None of the goodness begins until line30 so lets dissect the extension:

function forum_data()
    
{
    
global $IN;
    
$_POST["forum_title"] = $IN->GBL('title', 'POST'); //Get the title of your blog for use in forum title
$_POST["forum_id"] = 2; //The id of the forum where you want it posted
$_POST["forum_body"] = $IN->GBL('field_id_4', 'POST'); //the content to be used in the post

            
return;
    
}

Pretty straight forward… assuming you have only one weblog and only one field that you want posted, what happens if you have 2 weblogs (Work & Play)

Weblog: “Work” id = 12
“Work” weblogs posted to Forum ID = 2
3 Custom fields (id = 7,11,8) + Global field “summary”

Weblog: “Play” id=10
“Play” weblogs posted to Forum ID = 6
4 Custom fields (id= 13, 17, 14, 18) + Global field “entry_date”

Welcome to variables, you will need:
The ID of the custom fields (accessed thru the database not in the CP)
The ID of the weblogs (CP home>Admin>Weblog Administration>Weblog Management)
The IDs of the required topics in the forums (accessed thru CP home>Modules>Discussion Forum>YOURFORUM>Forum Board Home

function forum_data()
    
{
    
global $IN;
    
    if (
$IN->GBL('weblog_id', 'POST') == 12) //(Work Blogs ID)
        
{
        $_POST[
"forum_title"] = $IN->GBL('title', 'POST'); //Create the forum thread title from the actual weblog title
        
$_POST["forum_id"] = 2;//The forum ID to post in
        //Track all the fields you want
        
$variable01= $IN->GBL('field_id_7', 'POST'); //Get contents of field
        
$variable02= $IN->GBL('field_id_11', 'POST');//Get contents of field
        
$variable03= $IN->GBL('field_id_8', 'POST');//Get contents of field
        
$variable04= $IN->GBL('summary', 'POST');//Global field {summary}
        // If you want to create a link in your forums to the weblog
        
$backlink='<a href="http://yoursite.com/templatename{permalink}">Read Article</a>';
        
//This is where you construct the format of your post
        
$contents= "This is: $variable01 \n This is: $variable02 \r This is: $variable03 \n The summary: $variable04 \r \r $backlink";
        
$_POST["forum_body"] = $contents; //Assign $contents to the body of the post
        
}
         
elseif ($IN->GBL('weblog_id', 'POST') == 10) //(Play Blogs ID)
         
{
        $_POST[
"forum_title"] = $IN->GBL('title', 'POST'); //Create the forum thread title from the actual weblog title
        
$_POST["forum_id"] = 6;//The forum ID to post in
        //Track all the custom fields you want
        
$variable01= $IN->GBL('field_id_13', 'POST');//Get contents of field
        
$variable02= $IN->GBL('field_id_17', 'POST');//Get contents of field
        
$variable03= $IN->GBL('field_id_14', 'POST');//Get contents of field
        
$variable04= $IN->GBL('entry_date', 'POST');//Identify global field
        
$variable05= $IN->GBL('field_id_18', 'POST');//Get contents of field
        // If you want to create a link in your forums to the weblog
        
$backlink='<a href="http://yoursite.com/templatename{permalink}">Read Article</a>';
        
//This is where you construct the format of your post
        
$contents= "This is: $variable01 \n This is: $variable02 \r This is: $variable03 \r This is the entry date: $variable04 \r This is: $variable05 \r \r $backlink";
        
$_POST["forum_body"] = $contents; //Assign $contents to the body of the post
         
}

            
return;
    
}

The “if” statements could continue on indefinitely and if none of the criteria are met then it simply stops and doesn’t create a thread!

It may look daunting but if you have a rudimentary understanding of code then read this a couple of times and it should “gel”.

*This will not create a new forum category only a forum thread

Category:HowToCategory:Forums

Categories: