Last topic from the forum on site

Discussion forum for MOD Writers regarding MOD Development.
Locked
Granit
Registered User
Posts: 266
Joined: Sun Aug 27, 2006 3:17 pm

Last topic from the forum on site

Post 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.
User avatar
Nelsaidi
Registered User
Posts: 525
Joined: Mon Feb 11, 2008 1:59 pm
Location: London, UK
Contact:

Re: Last topic from the forum on site

Post 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,
Image
Click here to find out what eRepublik is.
Granit
Registered User
Posts: 266
Joined: Sun Aug 27, 2006 3:17 pm

Re: Last topic from the forum on site

Post 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.
User avatar
Nelsaidi
Registered User
Posts: 525
Joined: Mon Feb 11, 2008 1:59 pm
Location: London, UK
Contact:

Re: Last topic from the forum on site

Post 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 :)
Image
Click here to find out what eRepublik is.
Granit
Registered User
Posts: 266
Joined: Sun Aug 27, 2006 3:17 pm

Re: Last topic from the forum on site

Post 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.
User avatar
Nelsaidi
Registered User
Posts: 525
Joined: Mon Feb 11, 2008 1:59 pm
Location: London, UK
Contact:

Re: Last topic from the forum on site

Post 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
Image
Click here to find out what eRepublik is.
Granit
Registered User
Posts: 266
Joined: Sun Aug 27, 2006 3:17 pm

Re: Last topic from the forum on site

Post 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 :)
User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 17375
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Re: Last topic from the forum on site

Post 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>";
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.
User avatar
A_Jelly_Doughnut
Former Team Member
Posts: 34457
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run
Contact:

Re: Last topic from the forum on site

Post 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.
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish
User avatar
Nelsaidi
Registered User
Posts: 525
Joined: Mon Feb 11, 2008 1:59 pm
Location: London, UK
Contact:

Re: Last topic from the forum on site

Post by Nelsaidi »

Bah, my mistake then :( - Sorry.

Oh, and though so,

Code: Select all

,
also would work xD
Image
Click here to find out what eRepublik is.
User avatar
DavidIQ
Customisations Team Leader
Customisations Team Leader
Posts: 17375
Joined: Thu Jan 06, 2005 1:30 pm
Location: Fishkill, NY
Name: David Colón
Contact:

Re: Last topic from the forum on site

Post 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
Apply to become a Jr. Extension Validator
My extensions | In need of phpBB services? | Was I helpful today?
No unsolicited PMs unless you're planning on asking for paid help.
Locked

Return to “[3.0.x] MOD Writers Discussion”