1

Topic: Recent discussions code on front page

Kennel, could you be so kind to post the code here you are using for the "Recent discussions" box on the front page?
I would like to add this kind of recent discussions to my front page too; unfortunately I'm not that PHP/MySQL coder but better in cut & paste.
As long as I have a code I understand what it is doing, generating the code myself seems to be impossible... ;-)

Cheers and thanks ~ Arne

Re: Recent discussions code on front page

Why, sure :)

set_include_path(get_include_path().':../forums');

@include 'config.php';

// If config.php doesn't exist, PUN shouldn't be defined
if (!defined('PUN'))
    exit('config.php doesn\'t exist or is corrupt. Please run install.php to install PunBB first.');

define('PUN_DONT_UPDATE_COOKIE', 1);    // This will make sure that the forum doesn't set a new cookie for the visiting user
require 'include/common.php';

$result = $db->query('SELECT id, subject FROM '.$db->prefix.'topics WHERE moved_to IS NULL ORDER BY last_post DESC LIMIT 14') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());

while ($cur_topic = $db->fetch_assoc($result))
{
    if ($options['censoring'] == '1')
        $cur_topic['subject'] = censor_words($cur_topic['subject']);

    if (strlen($cur_topic['subject']) > 30)
        $cur_topic['subject'] = trim(substr($cur_topic['subject'], 0, 24)).' ...';

    echo "\t\t\t\t\t\t\t".'<b>·</b> <a href="http://punbb.org/forums/viewtopic.php?id='.$cur_topic['id'].'">'.htmlspecialchars($cur_topic['subject']).'</a><br>'."\n";
}

Please note two things however:

1. You have to enter the path to your forum root directory on the line stating "set_include_path". My path there is ../forums. Edit that line and enter the path to your forum root dir relative to where the script is located. This procedure is far from perfect. It has been greatly improved in an upcoming version of PunBB.

2. If you have any admin/mod only forums, topics from those forums will also be displayed (even if the visiting user is only a guest or a regular user). I'm going to fix that, but right now, I just don't have the time. I'm off to a wedding.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Recent discussions code on front page

I'm confused on how to utilize this this code for my index.php page so that the most recent posts show up.

Is this put into a php include file???

I need to have this feature for a website I am working on and I am under a tight timeline - any help would be GREATLY appreciated... smile

BTW - Of all the forum applications I have researched, I find this one the right balance of features and ease in customizing.

I look forward to further development.

Re: Recent discussions code on front page

Have a look at this topic: http://punbb.org/forums/viewtopic.php?id=2508

I want to add that doing what you want to do will be much easier in version 1.1 (that I'm currently working on).

And, thanks for the kind words :)

Edit: If you need further assistance, you can contact me over e-mail/ICQ/IRC.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

5

Re: Recent discussions code on front page

Kennel

IRC

where to find u?

Re: Recent discussions code on front page

Quakenet - #punbb

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Recent discussions code on front page

One small problem with the code though. It shows ALL recent discussions, including Admins/moderators only forums.

Re: Recent discussions code on front page

True. I've noted this before and all I can say is that you will have to wait for 1.1 :)

"Programming is like sex: one mistake and you have to support it for the rest of your life."

9 (edited by chacmool 2003-09-19 13:50)

Re: Recent discussions code on front page

I dont have time for that big_smile

$result = $db->query('SELECT t.id,t.subject FROM '.$db->prefix.'topics AS t,'.$db->prefix.'forums AS f WHERE t.forum_id=f.id AND f.admmod_only=0 AND t.moved_to IS NULL ORDER BY t.last_post LIMIT 14') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());

Re: Recent discussions code on front page

That's an option :)

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Recent discussions code on front page

$result = $db->query('SELECT t.id,t.subject FROM '.$db->prefix.'topics AS t,'.$db->prefix.'forums AS f WHERE t.forum_id=f.id AND f.admmod_only=0 AND t.moved_to IS NULL ORDER BY t.last_post LIMIT 14') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());

hmm,  i tried that and now i seem to be pulling topics that are pretty old.  im running ver 1.1.1 with the EAFM.  does that make a difference.

could somebody help me construct a statement?

Re: Recent discussions code on front page

Yeah, Chacmools code above sorts it the wrong way. Try this:

$result = $db->query('SELECT t.id,t.subject FROM '.$db->prefix.'topics AS t,'.$db->prefix.'forums AS f WHERE t.forum_id=f.id AND f.admmod_only=0 AND t.moved_to IS NULL ORDER BY t.last_post DESC LIMIT 14') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Recent discussions code on front page

hmm still selecting members only topics.  maybe i set it up wrong?  do you need more information about my database?

Re: Recent discussions code on front page

Members only topics?

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Recent discussions code on front page

oh.

http://www.f8klan.com/forum/index.php

im using the EAFM and created a members only section.  im not sure what i would need to show you to create the statement though.

Re: Recent discussions code on front page

Why do i get the message "Warning: Cannot modify header information - headers already sent"?

Re: Recent discussions code on front page

Jakob_j: You have to include the PunBB code before you output anything. E.g. put it at the top of you script.

"Programming is like sex: one mistake and you have to support it for the rest of your life."