1 (edited by Tubby 2007-04-20 09:54)

Topic: News Page

Well, i've been extremely bored lately and decided to code a little something tongue

What this code does is form a punbb page that retrieves "news" from a specific forum of your choice. You are also capable of setting a maximum amount of news to retrieve from the database. It's nothing special, but i hope that some of you will put this code to good use smile

<?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']) . ' / Home';
define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';
require PUN_ROOT.'include/parser.php';

// Load the forums.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';

// News Information
$news = '3';
$forum = '1';

// Retrieve News From Database
$db_news = $db->query('SELECT t.id, t.subject, t.num_replies, t.num_views, t.forum_id,  p.topic_id, p.poster, p.poster_id, p.message, p.hide_smilies, p.posted FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON t.id=p.topic_id AND p.posted=t.posted INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE t.forum_id='.$forum.' AND t.moved_to IS NULL AND f.redirect_url IS NULL ORDER BY t.posted DESC LIMIT '.$news) or error('Unable to fetch the portal news', __FILE__, __LINE__, $db->error());
                  
if ($db->num_rows($db_news))
{
    while($news = $db->fetch_assoc($db_news))
    {
        // Set Some Variables
        $message = parse_message($news['message'], $news['hide_smilies']);
        $subject = $news['subject'];
        $poster = '<a href="profile.php?id='.$news['poster_id'].'">'.$news['poster'].'</a>';
        $date_posted = format_time($news['posted']);
        $replies = $news['num_replies'];
        $views = $news['num_views'];
        $news_id = $news['id'];
        
        // Output News
        echo "\t\t\t\t".'<div class="blocktable" style="margin-bottom: 10px"><h2><span>'.$subject.'</span></h2><div class="box"><div class="inbox"><table cellspacing="0"><thead><tr><th class="tcl">'.$date_posted.' » by '.$poster.'</th></tr></thead><tbody><tr><td class="tcl"><div style="padding: 5px 2px 7px 5px">'.$message.'</div></td></tr></tbody><thead><tr><th class="tcl">Replies: '.$replies.' » Views: '.$views.' » <a href="post.php?tid='.$news_id.'">Post Reply</a></th></tr></thead></table></div></div></div>'."\n";
    }
}

// Require the footer
require PUN_ROOT.'footer.php';

Don't forget that you are able to configure the news information via these two lines:

// News Information
$news = '3';
$forum = '1';

A demo of this paticular page can be found here.

Re: News Page

a simpler version of the miniportal. i like it!

~James
FluxBB - Less is more

3

Re: News Page

thank you for that fast reply dr.jeckyl smile.

I kind of like the idea of using tables as you can see. I wanted to try outputing the news in a different way tongue. Do you have any suggestions as far as enhancing any of this code goes? I'm not the brightest bulb in the box when it comes to php.

Re: News Page

suggestion: make the title of each news story a link back to the thread. i know of the reply link but a guest gets an error page. also, take out the reply link for guests. other than those it's a great no hassle mod. big_smile

~James
FluxBB - Less is more

Re: News Page

another suggestion: at the very bottom between the last news block and the footer maybe put a link back to the news source's forum? "Archive..." or "More news..." maybe?

~James
FluxBB - Less is more

6

Re: News Page

some great ideas you have smile

i will most likely end up implementing these features as soon as possible ( probably when i get home this afternoon ).

Re: News Page

Tubby wrote:

i will most likely end up implementing these features as soon as possible ( probably when i get home this afternoon ).

any progress Tubby?

~James
FluxBB - Less is more

8 (edited by Tubby 2007-04-24 10:17)

Re: News Page

well, i've been holding off on this project mainly to think of a better way to implement the "archive" feature rather than just inserting a link. I cleaned it up a little bit and added a link directly to the topic. I have turned the text "Replies" in to a link. This was all done yesterday afternoon.

<?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']) . ' / News Page';
define('PUN_ALLOW_INDEX', 1);
require PUN_ROOT.'header.php';
require PUN_ROOT.'include/parser.php';

// Load the forums.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';

// News Information
$news = '2'; 
$forum = '1';

// Retrieve News From Database
$db_news = $db->query('SELECT t.id, t.subject, t.num_replies, t.num_views, t.forum_id,  p.topic_id, p.poster, p.poster_id, p.message, p.hide_smilies, p.posted FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON t.id=p.topic_id AND p.posted=t.posted INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE t.forum_id='.$forum.' AND t.moved_to IS NULL AND f.redirect_url IS NULL ORDER BY t.posted DESC LIMIT '.$news) or error('Unable to fetch the news', __FILE__, __LINE__, $db->error());

if($db->num_rows($db_news))
{
    while($news = $db->fetch_assoc($db_news))
    {
        // Set Some Variables
        $message = parse_message($news['message'], $news['hide_smilies']);
        $subject = $news['subject'];
        $poster = '<a href="profile.php?id='.$news['poster_id'].'">'.$news['poster'].'</a>';
        $date_posted = gmdate('F jS, Y', $news['posted']);
        $replies = $news['num_replies'];
        $views = $news['num_views'];
        $news_id = $news['id'];
        $news_output = '<div class="blocktable" style="margin-bottom: 10px"><h2><span>'.$subject.'</span></h2><div class="box"><div class="inbox"><table cellspacing="0"><thead><tr><th class="tcl">Posted by '.$poster.' on '.$date_posted.'</th></tr></thead><tbody><tr><td class="tcl"><div style="padding: 5px 2px 7px 5px">'.$message.'</div></td></tr></tbody><thead><tr><th class="tcl"><a href="viewtopic.php?id='.$news_id.'">Replies</a>: '.$replies.' | Views: '.$views.'</th></tr></thead></table></div></div></div>';
            
        echo $news_output;
            
    }
}
// Require the footer
require PUN_ROOT.'footer.php';

Re: News Page

COOL! can't wait to see the final one with the "archive" link. big_smile

~James
FluxBB - Less is more