Page 1 of 1

Last topic from the forum on site

Posted: Sat Jan 03, 2009 12:15 pm
by Granit
First of all i hope i am posting in the right forum.

I have a peace of code to show the last topic on my site.
No i wonder how to alter the code to me able to show the last activ topic and not just the last topic.
Also how to show date and time.

Here is the code that are in the single file on me server.

Code: Select all

<?php
/*
Plugin Name: WP-Phpbb Last Topics
Plugin URI: http://www.4mj.it/wordpress-phpbb-last-topics-plugin/
Description: Display the most recent topics of your phpBB forum.
Version: 1.1
Author: Peppe Argento
Author URI: http://www.4mj.it
****************************
Sorry for my english!
To exclude a category of the forum, like private forum, add AND forum_id !='2', whith the id you want exclude.
You can set the number of post to display in DESC LIMIT 0,10, where 10 is the number.
For example if you wanna exlude (id 2 e 11) write
$phpbbq = "SELECT * FROM ".$table_prefix."topics WHERE forum_id !='2' AND forum_id !='11' ORDER BY topic_last_post_id DESC LIMIT 0,10";
****************************
*/
function wpphpbb_topics() {
//set forum path, forum host
$forum_path = "";
$host = "";
include("".$forum_path."/config.php");
$connection = mysql_connect($dbhost, $dbuser, $dbpasswd);
$s_db = mysql_select_db($dbname, $connection);
$phpbbq = "SELECT * FROM ".$table_prefix."topics ORDER BY topic_last_post_id DESC LIMIT 0,5";
$results = mysql_query($phpbbq, $connection); 
while ($resultsow = mysql_fetch_array($results)) {
$topic_tit = $resultsow[topic_title];
// You can wrap long words below, where 60 is the lenght.
$topics_title = substr($topic_tit, 0, 25);
echo "<li><a href=\"$host"."/viewtopic.php?t=$resultsow[topic_id]\">$topics_title...</a></li>";
}
}
?>
And this is the code that i place on my site.

Code: Select all

<?php if (function_exists('wpphpbb_topics')): ?>
<? wpphpbb_topics(); ?>
<?php endif; ?>
Thank in advance.

Re: Last topic from the forum on site

Posted: Sun Jan 04, 2009 1:15 pm
by Nelsaidi

Code: Select all

<?php 
if(function_exists('wpphpbb_topics')){
wpphpbb_topics();
}
?>
(That wont work on a template btw )

The syntax you used was wrong,

Re: Last topic from the forum on site

Posted: Mon Jan 05, 2009 10:29 am
by Granit
It work for me on wordpress, the plugin is for wordpress and not for a phpbb template.

But i cant figure out how to be able to show the date and time.

Re: Last topic from the forum on site

Posted: Mon Jan 05, 2009 5:52 pm
by Nelsaidi
Sorry, didnt know

Read this

http://uk.php.net/date

The line under where i commented it out, or leave it and it will display the date like 27-11-2008 15:52:08

Code: Select all

    <?php
    /*
    Plugin Name: WP-Phpbb Last Topics
    Plugin URI: http://www.4mj.it/wordpress-phpbb-last-topics-plugin/
    Description: Display the most recent topics of your phpBB forum.
    Version: 1.1
    Author: Peppe Argento
    Author URI: http://www.4mj.it
    ****************************
    Sorry for my english!
    To exclude a category of the forum, like private forum, add AND forum_id !='2', whith the id you want exclude.
    You can set the number of post to display in DESC LIMIT 0,10, where 10 is the number.
    For example if you wanna exlude (id 2 e 11) write
    $phpbbq = "SELECT * FROM ".$table_prefix."topics WHERE forum_id !='2' AND forum_id !='11' ORDER BY topic_last_post_id DESC LIMIT 0,10";
    ****************************
    */
    function wpphpbb_topics() {
    //set forum path, forum host
    $forum_path = "";
    $host = "";
    include("".$forum_path."/config.php");
    $connection = mysql_connect($dbhost, $dbuser, $dbpasswd);
    $s_db = mysql_select_db($dbname, $connection);
    $phpbbq = "SELECT * FROM ".$table_prefix."topics ORDER BY topic_last_post_id DESC LIMIT 0,5";
    $results = mysql_query($phpbbq, $connection);
    while ($resultsow = mysql_fetch_array($results)) {
    $topic_tit = $resultsow[topic_title];
    // You can wrap long words below, where 60 is the lenght.
    $topics_title = substr($topic_tit, 0, 25);
    // Change whats AFTER date(' AND BEFORE ', 
    echo "<li><a href=\"$host"."/viewtopic.php?t=$resultsow[topic_id]\">$topics_title (Posted on ",date('d-m-Y H:i:s',$resultrow['topic_time'])</a></li>";
    }
    }
    ?>
It should work :)

Re: Last topic from the forum on site

Posted: Sat Jan 10, 2009 1:49 pm
by Granit
Hello and thanks for your help.

But when i try to do what you showed me a get this.

Parse error: syntax error, unexpected '/' in /wp-phpbb.php on line 31

I dont know how to solve that.

Re: Last topic from the forum on site

Posted: Sat Jan 10, 2009 3:47 pm
by Nelsaidi
Thanks, just noticed i left out a ," on line 31

Code: Select all

        <?php
        /*
        Plugin Name: WP-Phpbb Last Topics
        Plugin URI: http://www.4mj.it/wordpress-phpbb-last-topics-plugin/
        Description: Display the most recent topics of your phpBB forum.
        Version: 1.1
        Author: Peppe Argento
        Author URI: http://www.4mj.it
        ****************************
        Sorry for my english!
        To exclude a category of the forum, like private forum, add AND forum_id !='2', whith the id you want exclude.
        You can set the number of post to display in DESC LIMIT 0,10, where 10 is the number.
        For example if you wanna exlude (id 2 e 11) write
        $phpbbq = "SELECT * FROM ".$table_prefix."topics WHERE forum_id !='2' AND forum_id !='11' ORDER BY topic_last_post_id DESC LIMIT 0,10";
        ****************************
        */
        function wpphpbb_topics() {
        //set forum path, forum host
        $forum_path = "";
        $host = "";
        include("".$forum_path."/config.php");
        $connection = mysql_connect($dbhost, $dbuser, $dbpasswd);
        $s_db = mysql_select_db($dbname, $connection);
        $phpbbq = "SELECT * FROM ".$table_prefix."topics ORDER BY topic_last_post_id DESC LIMIT 0,5";
        $results = mysql_query($phpbbq, $connection);
        while ($resultsow = mysql_fetch_array($results)) {
        $topic_tit = $resultsow[topic_title];
        // You can wrap long words below, where 60 is the lenght.
        $topics_title = substr($topic_tit, 0, 25);
        // Change whats AFTER date(' AND BEFORE ', 
        echo "<li><a href=\"$host"."/viewtopic.php?t=$resultsow[topic_id]\">$topics_title (Posted on ",date('d-m-Y H:i:s',$resultrow['topic_time']),"</a></li>";
        }
        }
        ?>
That should work

Re: Last topic from the forum on site

Posted: Sat Jan 10, 2009 11:15 pm
by Granit
Now it works, but the date and time dont show correct.

This is what i get, Posted on 01-01-1970 01:00:00 :)

Re: Last topic from the forum on site

Posted: Sun Jan 11, 2009 4:22 am
by DavidIQ

Code: Select all

       echo "<li><a href=\"$host"."/viewtopic.php?t=$resultsow[topic_id]\">$topics_title (Posted on ",date('d-m-Y H:i:s',$resultrow['topic_time']),"</a></li>";
Not sure how that's even working (maybe echo identifying commas as something else) but the comma before and after your date() function there should be periods:

Code: Select all

       echo "<li><a href=\"$host"."/viewtopic.php?t=$resultsow[topic_id]\">$topics_title (Posted on " . date('d-m-Y H:i:s',$resultrow['topic_time']) . "</a></li>";

Re: Last topic from the forum on site

Posted: Sun Jan 11, 2009 7:31 pm
by A_Jelly_Doughnut
DavidIQ: echo treats a comma as a concatenation operator. One of the fun little facts about PHP :D

The problem with the code is a typo in the variable name.

Code: Select all

while ($resultsow = mysql_fetch_array($results)) {

Code: Select all

        echo "<li><a href=\"$host"."/viewtopic.php?t=$resultsow[topic_id]\">$topics_title (Posted on ",date('d-m-Y H:i:s',$resultrow['topic_time']),"</a></li>";
$resultsow and $resultrow are not the same variable :) Just change $resultrow['topic_time'] to $resultsow['topic_time'] and it should work.

Re: Last topic from the forum on site

Posted: Mon Jan 12, 2009 5:39 pm
by Nelsaidi
Bah, my mistake then :( - Sorry.

Oh, and though so,

Code: Select all

,
also would work xD

Re: Last topic from the forum on site

Posted: Mon Jan 12, 2009 6:04 pm
by DavidIQ
Yes...the comma will work. I figured echo was treating them as something else if it wasn't erroring but didn't realize it would be exactly like a period. :P