Topic: New topics instead of new posts

I've been searching, but can't find a solution and I don't think I can make it myself:
my members are asking for an option "show new topics", not meaning: "show new posts since last visit". They would like to have something like this, but then with just New Topics started since last visit. This is because I have a forum called "Show Off" and they would like to see just the new Show Off's.

Dit I overlook a mod or is this something that can easily be done?

Re: New topics instead of new posts

are you talking about a index page that displays the last  10 topics?

example: http://256studio.com
Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

Re: New topics instead of new posts

Well, I wasn't, because i'm not using a portal, but I think that can be a solution if I can change that to someting like 'Recent posts' with a link on the forum.
I found your mod, so I'm going to try this. Tnx!

Re: New topics instead of new posts

kewl, let me know if i can help..


Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

5 (edited by Marianne 2007-12-28 18:36)

Re: New topics instead of new posts

I managed to create a new page with your code in it and i modified it so it looks a bit like 'Recent topics' (and i'm a bit proud... i'm not a real coder wink)

There are 2 things i can't work out (is that english??):
- i want a column with the forum-name; i managed to make a column with replies (count) and start-date, but can't get the forum-name in a column ---> Done!
- i would like to have the icons (new topic/allready read topic) in front of the topics

This is my code (i used the this new page template):

<?php
 
define('PUN_ROOT', './');
define('PUN_QUIET_VISIT', 1);
require PUN_ROOT.'include/common.php';
 
//Set the page title here
$page_title = pun_htmlspecialchars($pun_config['o_board_title']) . ' / Nieuwste topics';
define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';
require PUN_ROOT.'include/parser.php';
 
?>
        <div class="block">
     <h2><span>Nieuwste topics</span></h2>
        <div> 
    
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<th class="tcl" scope="col"><?php echo $lang_common['Topic'] ?></th>
<th class="tc1" scope="col"><?php echo 'Door' ?></th>
<th class="tc1" scope="col"><?php echo $lang_common['Forum'] ?></th>
<th class="tc1" scope="col"><?php echo $lang_common['Replies'] ?></th>
<th class="tcr" scope="col"><?php echo 'Gestart' ?></th>
</tr>
          
<?php

showRecent(25); // Set amount of posts to be displayed here

function showRecent($show=5) {
    global $lang_common, $db, $pun_config, $db_prefix;

    $order_by = 't.posted';
    $forum_sql = '';

//$show = isset($_GET['show']) ? intval($_GET['show']) : 5;
        //if ($show < 1 || $show > 50) $show = 5;

$trunc_len = 50; // Set amount of text to be displayed in subject.

// Fetch $show topics
    $result = $db->query('SELECT t.id, t.poster, t.subject, t.posted, t.last_post, t.num_replies, t.forum_id FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id=3) WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.moved_to IS NULL'.$forum_sql.' ORDER BY '.$order_by.' DESC LIMIT '.$show) or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());


    
    
            while ($cur_topic = $db->fetch_assoc($result)) {
        if ($pun_config['o_censoring'] == '1')
     $cur_topic['subject'] = censor_words($cur_topic['subject']);
    $subject_truncated = pun_htmlspecialchars($cur_topic['subject']);
    
    
     


?>

<?php
    echo '<tr><td class="tcl">'.'<a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.pun_htmlspecialchars($cur_topic['subject']).'">'.substr($cur_topic['subject'], 0, $trunc_len).'</a></td>'.'<td class="tc1">'.$cur_topic['poster'].'</td><td class="tc2"></td><td class="tc3">'.$cur_topic['num_replies'].'</td><td class="tcr">'.format_time($cur_topic['posted'])."\n";
    }
    echo '</td></tr>';
    return;
}
?>
 

</td>
  </tr>
</table>
</div>
</div>
<?php
 
require PUN_ROOT.'footer.php';

Can you help me to get the forum-name in the output, and maybe the icons in front of the topic-titels?
I do know how to put the icons there, but don't know what code to use so the right icon (new/old) is in front of the topic-titel.

[edit]
I managed to get the forum-name in the output; so i'm just looking for a way to put the right icon in front of the topic-titels..

6 (edited by MattF 2007-12-28 20:42)

Re: New topics instead of new posts

If you look in index.php. search for the parts with the icon.inew, (I believe that's the default new icon, but may be incorrect), and the relevant code which sets the new/old icon status.

Edit:

There are 2 things i can't work out (is that english??)

That is perfectly valid English, btw. smile

Re: New topics instead of new posts

im looking at your code and i dont see the part with the icon_type in there. I even upload the script to my site and it is not there.

this is my index.php u will find the references to the $icon_type for the db query and the rest of the code.

i hope this will help you !


Q

<?php
define('PUN_PORTAL', 1); 
define('PUN_ROOT', './');
define('PUN_QUIET_VISIT', 1);
require PUN_ROOT.'include/common.php';
 
$page_title = pun_htmlspecialchars($pun_config['o_board_title']);
define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';
require PUN_ROOT.'include/parser.php';
 
function pun_news($fid='', $show=15, $truncate=1)
{
    global $lang_common, $db, $pun_config, $db_prefix;
    $max_subject_length = 30;
    $show_max_topics = 50;
    $fid = intval($fid);
    $order_by = 't.posted';
    $forum_sql = '';
    // Was a forum ID supplied?
    if ( $fid ) $forum_sql = 'f.id='.$fid.' AND ';
    $show = intval($show);
    if ($show < 1 || $show > $show_max_topics)
    $show = 15;
    $saveddate="";
    // Fetch $show topics
    $result = $db->query('SELECT t.id, t.poster, t.subject, t.posted, t.last_post, f.id AS fid, f.forum_name FROM '.$db_prefix.'topics AS t INNER JOIN '.$db_prefix.'forums AS f ON t.forum_id=f.id WHERE f.id='.$fid.' AND t.moved_to IS NULL ORDER BY '.$order_by.' DESC') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
    $show_count = 0;
    if ( !$db->num_rows($result) ) return $output;
    while ( ($show_count < $show) && ($cur_topic = $db->fetch_assoc($result)) ) {
        $temp = '';
        if ($pun_config['o_censoring'] == '1')
            $cur_topic['subject'] = censor_words($cur_topic['subject']);
        if (pun_strlen($cur_topic['subject']) > $max_subject_length)
            $subject_truncated = trim(substr($cur_topic['subject'], 0, ($max_subject_length-5))).' ...';
        else
            $subject_truncated = $cur_topic['subject'];
        $newsheading = '<a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.pun_htmlspecialchars($cur_topic['subject']).'">'.pun_htmlspecialchars($subject_truncated).'</a> - <em>Posted by '.$cur_topic['poster'].' at '.date('h:i A', $cur_topic['posted']).'</em><br />';
        // Group posts by date    
        $thisdate = date('l, d F Y', $cur_topic['posted']);
        if ($thisdate != $saveddate) 
 
        {
            if ($saveddate)
            {
                $temp .= "</div></div>";
            }
            $temp .= '<div class="block"><h2><span>'.$thisdate.'</span></h2><div class="box"><div class="inbox"><p>';
            $saveddate = $thisdate;
        }
        else {
            $temp .= '<div class="inbox"><p>';
        }
        $temp .= $newsheading.'</p>';
        $id = $cur_topic['id'];
        $msg = $db->query('SELECT id, poster, poster_id, poster_ip, poster_email, message, posted, edited, edited_by FROM '.$db_prefix.'posts WHERE topic_id='.$id.' LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
            if ( !$db->num_rows($msg) ) continue;
        $cur_post = $db->fetch_assoc($msg);
        // Display first paragraph only (comment out next four lines to turn off)
        if ($truncate == 1)
        {
        $paragraph = preg_split("/s*n+/", $cur_post['message']);
            if (isset($paragraph[1])) {
                $cur_post['message'] = $paragraph[0] . "...";
            }
        }
        $cur_post['message'] = parse_message($cur_post['message'], 0);
        $temp .= $cur_post['message'];
        $temp .= "</div>";
        if (isset($output)) {
            $output .= $temp;
        }
        else {
            $output = $temp;
        }
        ++$show_count;
    } // end of while
    $output .= "</div></div>";
    return $output;
}
?>
  
        <?php
/*

PunBB Active Topics

Copyright 2004-2005 Alex King, http://www.alexking.org/

This is a mod for PunBB, http://www.punbb.org/
PunBB is Copyright (C) 2002, 2003, 2004  Rickard Andersson (rickard@punbb.org)

This file is based on the viewtopic.php file in PunBB.

-------------------------------

You can see this in action at the Use Tasks forums:

  http://www.usetasks.com/forums/


To install, include this file below the forums list in your index.php file:



  include('mod_active_topics_1.2.php');

*/

$ak_limit = 10; // change this to the number of active topics you want to display.

$result = $db->query('
    SELECT t.* 
    FROM '.$db->prefix.'topics AS t 
    INNER JOIN '.$db->prefix.'forums AS f 
    ON f.id=t.forum_id 
    LEFT JOIN '.$db->prefix.'forum_perms AS fp 
    ON (
        fp.forum_id=f.id 
        AND fp.group_id='.$pun_user['g_id'].'
    ) 
    WHERE (
        fp.read_forum IS NULL 
        OR fp.read_forum=1
    ) 
    ORDER BY t.last_post DESC
    LIMIT '.$ak_limit
) or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());

require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';

?>

<div id="vf" class="blocktable">
    <h2><span>Recent Posts</span></h2>
    <div class="box">
        <div class="inbox">
            <table cellspacing="0">
            <thead>
                <tr>
                    <th class="tcl" scope="col"><?php echo $lang_common['Topic'] ?></th>
                    <th class="tc2" scope="col"><?php echo $lang_common['Replies'] ?></th>
                    <th class="tc3" scope="col"><?php echo $lang_forum['Views'] ?></th>
                    <th class="tcr" scope="col"><?php echo $lang_common['Last post'] ?></th>
                </tr>
            </thead>
            <tbody>
<?php
// If there are topics in this forum.
if ($db->num_rows($result))
{
    while ($cur_topic = $db->fetch_assoc($result))
    {
        $icon_text = $lang_common['Normal icon'];
        $item_status = '';
        $icon_type = 'icon';

        if ($cur_topic['moved_to'] == null)
            $last_post = '<a href="viewtopic.php?pid='.$cur_topic['last_post_id'].'#p'.$cur_topic['last_post_id'].'">'.format_time($cur_topic['last_post']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['last_poster']).'</span>';
        else
            $last_post = ' ';

        if ($pun_config['o_censoring'] == '1')
            $cur_topic['subject'] = censor_words($cur_topic['subject']);

        if ($cur_topic['moved_to'] != 0)
            $subject = $lang_forum['Moved'].': <a href="viewtopic.php?id='.$cur_topic['moved_to'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>';
        else if ($cur_topic['closed'] == '0')
            $subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>';
        else
        {
            $subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>';
            $icon_text = $lang_common['Closed icon'];
            $item_status = 'iclosed';
        }

        if (!$pun_user['is_guest'] && $cur_topic['last_post'] > $pun_user['last_visit'] && $cur_topic['moved_to'] == null)
        {
            $icon_text .= ' '.$lang_common['New icon'];
            $item_status .= ' inew';
            $icon_type = 'icon inew';
            $subject = '<strong>'.$subject.'</strong>';
            $subject_new_posts = '<span class="newtext">[ <a href="viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.$lang_common['New posts info'].'">'.$lang_common['New posts'].'</a> ]</span>';
        }
        else
            $subject_new_posts = null;

        // Should we display the dot or not? :)
        if (1 == 0 && !$pun_user['is_guest'] && $pun_config['o_show_dot'] == '1')
        {
            if ($cur_topic['has_posted'] == $pun_user['id'])
                $subject = '<strong>·</strong> '.$subject;
            else
                $subject = '  '.$subject;
        }

        if ($cur_topic['sticky'] == '1')
        {
            $subject = '<span class="stickytext">'.$lang_forum['Sticky'].': </span>'.$subject;
            $item_status .= ' isticky';
            $icon_text .= ' '.$lang_forum['Sticky'];
        }

        $num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / $pun_user['disp_posts']);

        if ($num_pages_topic > 1)
            $subject_multipage = '[ '.paginate($num_pages_topic, -1, 'viewtopic.php?id='.$cur_topic['id']).' ]';
        else
            $subject_multipage = null;

        // Should we show the "New posts" and/or the multipage links?
        if (!empty($subject_new_posts) || !empty($subject_multipage))
        {
            $subject .= '  '.(!empty($subject_new_posts) ? $subject_new_posts : '');
            $subject .= !empty($subject_multipage) ? ' '.$subject_multipage : '';
        }

?>
                <tr<?php if ($item_status != '') echo ' class="'.trim($item_status).'"'; ?>>
                    <td class="tcl">
                        <div class="intd">
                            <div class="<?php echo $icon_type ?>"><div class="nosize"><?php echo trim($icon_text) ?></div></div>
                            <div class="tclcon">
                                <?php echo $subject."\n" ?>
                            </div>
                        </div>
                    </td>
                    <td class="tc2"><?php echo ($cur_topic['moved_to'] == null) ? $cur_topic['num_replies'] : ' ' ?></td>
                    <td class="tc3"><?php echo ($cur_topic['moved_to'] == null) ? $cur_topic['num_views'] : ' ' ?></td>
                    <td class="tcr"><?php echo $last_post ?></td>
                </tr>
<?php

    }
}
else
{

?>
                <tr>
                    <td class="tcl" colspan="4"><?php echo $lang_forum['Empty forum'] ?></td>
                </tr>
<?php

}

?>
            </tbody>
            </table>
        </div>
    </div>
</div>

       <?php
echo pun_news(1, 5, 0);
 
require PUN_ROOT.'footer.php';
My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

Re: New topics instead of new posts

It took quite a while (did i say i'm not a coder? wink) but i managed to make a real 'recent topics'-page, with workin icons and column with author and forum! It's a bit of your (=quaker) index.php, a bit of your other code and a little bit of me wink
Thank you very much!!

Re: New topics instead of new posts

post ur code if you dont mind... maybe someone else could use it?
or maybe we could make it better..haha


Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

Re: New topics instead of new posts

Ow.. euhm.. hm.. i'm not that proud of my code, it wòrks...  Please don't laugh at my solutions wink

<?php
define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
 
$page_title = pun_htmlspecialchars($pun_config['o_board_title']);
define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';
require PUN_ROOT.'include/parser.php';
 

  
        
/*

PunBB Active Topics

Copyright 2004-2005 Alex King, http://www.alexking.org/

This is a mod for PunBB, http://www.punbb.org/
PunBB is Copyright (C) 2002, 2003, 2004  Rickard Andersson (rickard@punbb.org)

This file is based on the viewtopic.php file in PunBB.

-------------------------------

You can see this in action at the Use Tasks forums:

  http://www.usetasks.com/forums/


To install, include this file below the forums list in your index.php file:



  include('mod_active_topics_1.2.php');

*/

$ak_limit = 30; // change this to the number of active topics you want to display.

$result = $db->query('
    SELECT t.*, f.forum_name 
    FROM '.$db->prefix.'topics AS t 
    INNER JOIN '.$db->prefix.'forums AS f 
    ON f.id=t.forum_id 
    AND t.forum_id IN ("3","30", "31")
    LEFT JOIN '.$db->prefix.'forum_perms AS fp 
    ON (
        fp.forum_id=f.id 
        AND fp.group_id='.$pun_user['g_id'].'
    ) 
    WHERE (
        fp.read_forum IS NULL 
        OR fp.read_forum=1
    ) 
    ORDER BY t.posted DESC
    LIMIT '.$ak_limit
) or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());

require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';

?>

<div id="vf" class="blocktable">
    <h2><span>Nieuwe topics uit de categorie "Show Off"</span></h2>
    <div class="box">
        <div class="inbox">
            <table cellspacing="0">
            <thead>
                <tr>
                    <th class="tcl" scope="col" width="200px"><?php echo $lang_common['Topic'] ?></th>
                    <th class="tc2" scope="col" style="width:45px;"><?php echo "Door" ?></th>
                    <th class="tcl" scope="col" style="width:60px"><?php echo $lang_common['Forum'] ?></th>
                    <th class="tc3" scope="col" style="width:40px;"><?php echo $lang_common['Replies'] ?></th>
                    <th class="tcr" scope="col" style="width:60px;"><?php echo "Gestart" ?></th>
                </tr>
            </thead>
            <tbody>
<?php
// If there are topics in this forum.
if ($db->num_rows($result))
{
    while ($cur_topic = $db->fetch_assoc($result))
    {
        $icon_text = $lang_common['Normal icon'];
        $item_status = '';
        $icon_type = 'icon';

        if ($cur_topic['moved_to'] == null)
            $last_post = '<a href="viewtopic.php?pid='.$cur_topic['last_post_id'].'#p'.$cur_topic['last_post_id'].'">'.format_time($cur_topic['last_post']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['last_poster']).'</span>';
        else
            $last_post = ' ';

        if ($pun_config['o_censoring'] == '1')
            $cur_topic['subject'] = censor_words($cur_topic['subject']);

        if ($cur_topic['moved_to'] != 0)
            $subject = $lang_forum['Moved'].': <a href="viewtopic.php?id='.$cur_topic['moved_to'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> ';
        else if ($cur_topic['closed'] == '0')
            $subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a>';
        else
        {
            $subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> ';
            $icon_text = $lang_common['Closed icon'];
            $item_status = 'iclosed';
        }

        if (!$pun_user['is_guest'] && $cur_topic['last_post'] > $pun_user['last_visit'] && $cur_topic['moved_to'] == null)
        {
            $icon_text .= ' '.$lang_common['New icon'];
            $item_status .= ' inew';
            $icon_type = 'icon inew';
            $subject = '<strong>'.$subject.'</strong>';
            $subject_new_posts = '<span class="newtext">[ <a href="viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.$lang_common['New posts info'].'">'.$lang_common['New posts'].'</a> ]</span>';
        }
        else
            $subject_new_posts = null;

        // Should we display the dot or not? :)
        if (1 == 0 && !$pun_user['is_guest'] && $pun_config['o_show_dot'] == '1')
        {
            if ($cur_topic['has_posted'] == $pun_user['id'])
                $subject = '<strong>·</strong> '.$subject;
            else
                $subject = '  '.$subject;
        }

        if ($cur_topic['sticky'] == '1')
        {
            $subject = '<span class="stickytext">'.$lang_forum['Sticky'].': </span>'.$subject;
            $item_status .= ' isticky';
            $icon_text .= ' '.$lang_forum['Sticky'];
        }

        $num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / $pun_user['disp_posts']);

        if ($num_pages_topic > 1)
            $subject_multipage = '[ '.paginate($num_pages_topic, -1, 'viewtopic.php?id='.$cur_topic['id']).' ]';
        else
            $subject_multipage = null;

        // Should we show the "New posts" and/or the multipage links?
        if (!empty($subject_new_posts) || !empty($subject_multipage))
        {
            $subject .= '  '.(!empty($subject_new_posts) ? $subject_new_posts : '');
            $subject .= !empty($subject_multipage) ? ' '.$subject_multipage : '';
        }
        
//gebruikersnaam maximaal 9 karakters

$suffix = "..";
$maxChar = 9;

if (strlen($cur_topic['poster']) > $maxChar){
    $cur_topic['poster'] = substr($cur_topic['poster'],0,$maxChar);
    $cur_topic['poster'] = $cur_topic['poster'] . $suffix;
    }

?>
                <tr<?php if ($item_status != '') echo ' class="'.trim($item_status).'"'; ?>>
                    <td class="tcl">
                        <div class="intd">
                            <div class="<?php echo $icon_type ?>"><div class="nosize"><?php echo trim($icon_text) ?></div></div>
                            <div class="tclcon">
                                <?php echo $subject."\n" ?>
                            </div>
                        </div>
                    </td>
                    <td class="tc2" style="text-align:left;"><?php echo pun_htmlspecialchars($cur_topic['poster']) ?></td>
                    <td class="tc2" style="text-align:left;"><?php echo '<a href="'.$pun_config['o_base_url'].'/viewforum.php?id='.$cur_topic['forum_id'].'">'.$cur_topic['forum_name'].'</a>' ?></td>
                    <td class="tc3"><?php echo ($cur_topic['moved_to'] == null) ? $cur_topic['num_replies'] : ' ' ?></td>
                    <td class="tcr"><?php echo format_time($cur_topic['posted']) ?></td>
                </tr>
<?php

    }
}
else
{

?>
                <tr>
                    <td class="tcl" colspan="4"><?php echo $lang_forum['Empty forum'] ?></td>
                </tr>
<?php

}

?>
            </tbody>
            </table>
        </div>
    </div>
</div>

<?php
 
require PUN_ROOT.'footer.php';

I changed the query for $result  and euhm.. in holland we say 'that doesn't deserve a beautycontest-price'  yikes
And that's the same with the styles of the <td>'s.

Be gentle wink

11 (edited by TheSearcher 2011-05-09 16:41)

Re: New topics instead of new posts

Hi  smile

First congratulations for the code, it works perfectly

I would need to have actually all the topics of the forum with pagination

ie not only the xxx last topics but all of them ordered by date with pagination

I tried a lot of things : trying to modify search.php, trying to add pagination to this code above

but i dont know what is the good way to do it

Thank you very much for your help  smile

Alice