Wordpress last phpbb3 topics code

Discussion forum for MOD Writers regarding MOD Development.

Wordpress last phpbb3 topics code

Postby Brandpreventie » Mon Mar 17, 2008 9:30 pm

I want to see the latest phpbb3 topics in a wordpress widget. I found some code somewhere on the internet, it works reasonably good.
Code: Select all
<?php
$connection = mysql_connect(localhost,"USER","PASSWORD") or die("Service temporairly unavailable");
$db = mysql_select_db("DATABASE",$connection) or die("Service temporairly unavailable");
$sql = "select * from phpbb_topics order by topic_last_post_time desc limit 0,10";
$result = mysql_query($sql) or die("Service temporairly unavailable");
for($x=1;$x<=10;$x++){
   $row = mysql_fetch_array($result);
   echo "<a href = \"http://www.domain.nl/viewtopic.php?f=$row[forum_id]&t=$row[topic_id]\">$row[topic_title]</a><br>";
}


but the only problem is, that is alsow shows the hidden topic's, does anyone know a simple way to filter this? (for instance with forumid's in php code)
Brandpreventie
Registered User
 
Posts: 28
Joined: Wed May 03, 2006 9:41 am

Re: Wordpress last phpbb3 topics code

Postby A_Jelly_Doughnut » Tue Mar 18, 2008 12:27 am

Code: Select all
$sql = "select * from phpbb_topics order by topic_last_post_time desc limit 0,10";


Change that to:
Code: Select all
$sql = "select * from phpbb_topics WHERE forum_id IN (2, 3, 5) order by topic_last_post_time desc limit 0,10";


Replace 2, 3, 5 with the list of forums for which you want to allow the topics to appear in Wordpress.
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish

Celebrating 11 years as a phpBB user
User avatar
A_Jelly_Doughnut
Former Team Member
 
Posts: 34391
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run

Re: Wordpress last phpbb3 topics code

Postby NYXX » Sat Mar 22, 2008 1:33 am

I've tried this but I'm getting the following error message

$row[topic_title]
"; }
NYXX
Registered User
 
Posts: 61
Joined: Fri Sep 16, 2005 2:19 am

Re: Wordpress last phpbb3 topics code

Postby Brf » Sat Mar 22, 2008 11:50 am

Well... that is what you are echoing.
If you want to parse an array within a string, you would have to use braces...

Code: Select all
 echo "<a href = \"http://www.domain.nl/viewtopic.php?f={$row[forum_id]}&t={$row[topic_id]}\">$row{[topic_title]}</a><br>";
User avatar
Brf
Support Team Member
Support Team Member
 
Posts: 46788
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Wordpress last phpbb3 topics code

Postby NYXX » Sat Mar 22, 2008 8:23 pm

So is this correct

<?php
$connection = mysql_connect(localhost,"nyxx_phpb1","oGg6{pHEwg7M") or die("Service temporairly unavailable");
$db = mysql_select_db("nyxx_phpb1",$connection) or die("Service temporairly unavailable");
$sql = "select * from phpbb_topics WHERE forum_id IN (2, 3, 5) order by topic_last_post_time desc limit 0,10";
$result = mysql_query($sql) or die("Service temporairly unavailable");
for($x=1;$x<=10;$x++){
$row = mysql_fetch_array($result);
echo "<a href = \"http://mamtor2.nyxxunderground.com/viewtopic.php?f=4&t=10{$row[forum_id]}&t={$row[topic_id]}\">$row{[topic_title]}</a><br>";
}
NYXX
Registered User
 
Posts: 61
Joined: Fri Sep 16, 2005 2:19 am

Re: Wordpress last phpbb3 topics code

Postby NYXX » Sun Mar 23, 2008 4:35 am

BUMP
NYXX
Registered User
 
Posts: 61
Joined: Fri Sep 16, 2005 2:19 am

Re: Wordpress last phpbb3 topics code

Postby Brf » Sun Mar 23, 2008 11:51 am

No. We both missplaced a {
You need both {} around any array in a string.

It should be {$row[topic_title]}
User avatar
Brf
Support Team Member
Support Team Member
 
Posts: 46788
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Wordpress last phpbb3 topics code

Postby NYXX » Sun Mar 23, 2008 2:06 pm

Still getting this error

{$row[topic_title]}
";}
NYXX
Registered User
 
Posts: 61
Joined: Fri Sep 16, 2005 2:19 am

Re: Wordpress last phpbb3 topics code

Postby A_Jelly_Doughnut » Sun Mar 23, 2008 2:43 pm

Code: Select all
<?php
$connection = mysql_connect(localhost,"nyxx_phpb1","oGg6{pHEwg7M") or die("Service temporairly unavailable");
$db = mysql_select_db("nyxx_phpb1",$connection) or die("Service temporairly unavailable");
$sql = "select * from phpbb_topics WHERE forum_id IN (2, 3, 5) order by topic_last_post_time desc limit 0,10";
$result = mysql_query($sql) or die("Service temporairly unavailable");
for($x=1;$x<=10;$x++){
$row = mysql_fetch_array($result);
echo "<a href = \"http://mamtor2.nyxxunderground.com/viewtopic.php?f=4&t=10{$row['forum_id']}&t={$row['topic_id']}\">{$row['topic_title']}</a><br />";
}


Try that ... I believe you were misusing the {} operators
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish

Celebrating 11 years as a phpBB user
User avatar
A_Jelly_Doughnut
Former Team Member
 
Posts: 34391
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run

Re: Wordpress last phpbb3 topics code

Postby NYXX » Mon Mar 24, 2008 3:17 am

Sorry.
Last edited by NYXX on Mon Mar 24, 2008 1:39 pm, edited 1 time in total.
NYXX
Registered User
 
Posts: 61
Joined: Fri Sep 16, 2005 2:19 am

Re: Wordpress last phpbb3 topics code

Postby Paul » Mon Mar 24, 2008 9:58 am

I have removed your database passwords, and username, be sure you change them for security reasons ;).
Its a pretty bad idea to post that kind of things here.
Knock knock
Race condition
Who's there?
User avatar
Paul
MOD Team Member
MOD Team Member
 
Posts: 17546
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier

Re: Wordpress last phpbb3 topics code

Postby NYXX » Mon Mar 24, 2008 1:43 pm

Sorry. I was wondering if there was an easier way of linking my Forum Topics or Posts to my Wordpress.

I'm actually suprised that with Phpbb3 there is no RSS Feed capablity yet.
NYXX
Registered User
 
Posts: 61
Joined: Fri Sep 16, 2005 2:19 am

Re: Wordpress last phpbb3 topics code

Postby Da^MsT » Tue Apr 08, 2008 11:42 am

A_Jelly_Doughnut wrote:
Code: Select all
<?php
$connection = mysql_connect(localhost,"nyxx_phpb1","oGg6{pHEwg7M") or die("Service temporairly unavailable");
$db = mysql_select_db("nyxx_phpb1",$connection) or die("Service temporairly unavailable");
$sql = "select * from phpbb_topics WHERE forum_id IN (2, 3, 5) order by topic_last_post_time desc limit 0,10";
$result = mysql_query($sql) or die("Service temporairly unavailable");
for($x=1;$x<=10;$x++){
$row = mysql_fetch_array($result);
echo "<a href = \"http://mamtor2.nyxxunderground.com/viewtopic.php?f=4&t=10{$row['forum_id']}&t={$row['topic_id']}\">{$row['topic_title']}</a><br />";
}


Try that ... I believe you were misusing the {} operators


Can you get more information like topic starter, last topic poster, time, date, forum category out of this?
User avatar
Da^MsT
Registered User
 
Posts: 40
Joined: Tue Jun 12, 2007 11:16 am
Location: Sweden

Re: Wordpress last phpbb3 topics code

Postby netors( ) » Mon Jan 18, 2010 6:04 pm

So... I want to contribute something to this thread. I develop my own code, because i was searching and searching and searching... and all the codes I found doesn't work fine (for me). So... I hope, this can help to some one else....

Put this code in wordpress/wp-content/your-theme/sidebar.php

Code: Select all
<ul>
<?php
// fill with your db acces information
$d_bhost = ''; // host (localhost, 06.mysqlprovider.com)
$db_name = ''; // your data base name
$db_user = ''; // your data base user name
$db_pass = ''; // your data base password

$prefix = 'phpbb_'; // the prefix of yours pbpbb tables (phpbb_ by default)
$dir = 'http://foro.gekkotaku.com/'; // this is your foro address
$msg_display = 7; // number of displays you need

// follow my syntax for exclude your hidden or private forums...
// if you dont know how id have your hidden forums, just go to your hidden forum, check your direction bar (in your navigator, EX. firefox, explorer)
// and put atention on this: viewforum.php?f=8
// f - means forum, in this case, my hidden forum is the id - 8
$hidden_forum = "post.forum_id <> 12 AND post.forum_id <> 33 AND post.forum_id <> 36"; // the syntax: post.forum_id <> hiden-forum-id (dont forget add an AND syntax for a new condition)


// if you dont have experience on programming... dont touch this
$conn = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db($db_name,$conn);

$sql = "
   SELECT forum.forum_name, post.forum_id, post.post_text, topic.topic_id, topic.topic_title, topic.topic_replies, topic.topic_last_post_id, user.username
   FROM '.$prefix.'posts post
   LEFT JOIN '.$prefix.'forums forum ON post.forum_id = forum.forum_id
   LEFT JOIN '.$prefix.'users user ON post.poster_id = user.user_id
   LEFT JOIN '.$prefix.'topics topic ON post.topic_id = topic.topic_id
   WHERE
   '.$hidden_forum.'
   ORDER BY post.post_time DESC LIMIT $msg_display
   ";
$result = mysql_query($sql);

while ($rows = mysql_fetch_array($result)) {
   $start = round($rows[topic_replies] / 10).'0';
   $rows[post_text] = preg_replace("(\[.+?\])is",'',$rows[post_text]); // to exclude phpbb code
   $rows[post_text] = substr($rows[post_text],0,80)."..."; // to limit to XX chars
   
   echo "<li>";
   echo '<a href="'.$dir.'viewtopic.php?f='.$rows[forum_id].'&t='.$rows[topic_id].'&start='.$start.'#p'.$rows[topic_last_post_id].'" title="'.$rows[post_text].'" role="visit gekkOtaku.com" target="_blank">'.$rows[username].' on: '.$rows[forum_name].' &raquo; '.$rows[topic_title].'</a>';
   echo "</li>";
}

mysql_free_result($result);
mysql_close($conn);
?>
</ul>


The code display what user say and where:
User on: Foro Name > Topic Title.

Whe mouse over the link, display the tittle of link with short text from what user say.

I get the id for the forum, topic, user, post... to display in the link, also, get the title and names. With this, we show more especific information than just a topic info...

If you wana see how it works or how display the results, just go to: http://www.gekkotaku.com
I stay connect for any question.
;)
Last edited by netors( ) on Thu Feb 11, 2010 5:30 am, edited 11 times in total.

Loading life. Please wait...
* Reading files needed to boot [ ok ] * Starting basic networking [ ok ] <--- me conecto, luego existo
gekkO OS 1.0 bootstrap tty1 i686 GNU/Linux
Password: ******
iiO@netOrX :: [~]$ _
User avatar
netors( )
Registered User
 
Posts: 9
Joined: Mon Jan 18, 2010 5:38 pm
Location: Puerto Vallarta, Jal

Re: Wordpress last phpbb3 topics code

Postby netors( ) » Thu Feb 11, 2010 12:21 am

I'm back. This time with a plugin and improved version. I hope it useful.

Basic instructions:
Unzip the file, put it into de plugin folder (wp-content/plugins/)
Go to de WordPress Admin panel
Go to the plugins menu and activate the plugin

* Follow the instructions into the file.

Finally, copy the function and paste it somewhere of your template
Example:
Code: Select all
<ul>
<?php lastPhpbbTopic('displays=8&char_limit=100'); ?>
</ul>


And here are the default arguments~
Code: Select all
$defaults = array(
      'location' => 1,
      'displays' => 3,
      'before' => '<li>',
      'after' => '</li>',
      'table_prefix' => 'phpbb_',
      'char_limit' => 80,
      'dir' => 'http://foro.gekkotaku.com/' // this is your foro address, CHANGE BY YOUR OWN
   );



If have any questions... i'll be in touch.

UPDATE:
DOWNLOAD FROM WP CODEX

*NOTE: this code was born in http://www.gekkotaku.com, so, you can download at the forum too. You cand found this code into the CODEX of WordPress too.
Last edited by netors( ) on Mon Feb 15, 2010 10:27 pm, edited 2 times in total.

Loading life. Please wait...
* Reading files needed to boot [ ok ] * Starting basic networking [ ok ] <--- me conecto, luego existo
gekkO OS 1.0 bootstrap tty1 i686 GNU/Linux
Password: ******
iiO@netOrX :: [~]$ _
User avatar
netors( )
Registered User
 
Posts: 9
Joined: Mon Jan 18, 2010 5:38 pm
Location: Puerto Vallarta, Jal

Next

Return to [3.0.x] MOD Writers Discussion

Who is online

Users browsing this forum: No registered users and 21 guests