Topic: Mini News

Hey I got the mini portal and I want to display news on it but when I put the forum id of news it still dosent display on my portal I put this


function pun_news($fid='4', $show=15, $truncate=1)  <--- with 4 being the id i want

please help if you have time of course

2

Re: Mini News

Bounty-Hunter wrote:

function pun_news($fid='4', $show=15, $truncate=1)  <--- with 4 being the id i want

please help if you have time of course

do u put that in the code near the top by any chance?
if you look on the bottom of that code there is a space to put your forum id there.

Re: Mini News

i dunno it looks like where i put it is correct there is multiple other places that say id but yes i put it at the top if there is another place please post

Re: Mini News

you edited the wrong line, you are meant to edit the one lower down.

Re: Mini News

how can I get it to display more text in the news item being displayed. If I set it to truncate at 1 then it only shows me approximately 5 letters like this example:


Whe...

I would like to be able to set it to something like 250 characters. Also, is there a way to have alink that says read more and it then takes you to the full topic in the forum?

Thanks
Bingiman

Re: Mini News

anyone?

Re: Mini News

Theres no need to bump posts so quickly, be patient.

Re: Mini News

What about now? Is it a good time to bump? I can't believe no one can help me on this.

Re: Mini News

dude, your a canadian... you should know this stuff tongue
is this the mod with a "front page" and the 3 param function call? you try setting truncate to 250? XD
Also... ummm, look at the mod's code... somewhere in that function that you call, it should find the topic_id. from that you can create a "comments" link.
I'm guessing you want something like the frontpage on my site? with the comments link and the number of comments?

echo "deadram"; echo; fortune;

Re: Mini News

Well, I added the comments like on your page but I can't figure out how to truncate at 250. I am using the miniportal hack and I am just totally lost as to how I can do it.

Bingiman

Re: Mini News

Here is my index file. Hopefully you can help me with it.

<?php
 
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, t.num_replies, 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 = '<div style="margin-top:-8px;"><a class="news-links" 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><br /><em>Posted by <b>'.$cur_topic['poster'].'</b> at '.date('h:i A', $cur_topic['posted']).'</em><br /><a href="'.$pun_config['o_base_url'].'/viewtopic.php?id='.$cur_topic['id'].'&action=new" title="'.pun_htmlspecialchars($cur_topic['subject']).'">'.$cur_topic['num_replies'].' Comments...</a></div>';
        // 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"><br />';
            $saveddate = $thisdate;
        }
        else {
            $temp .= '<div class="inbox"><br />';
        }
        $temp .= $newsheading.'<br />';
        $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;
}
?>
 
        <div class="block">
            <h2><span>Welcome</span></h2>
            <div class="box">
                <div class="inbox">
Welcome
                </div>
            </div>
        </div>
<?php
echo pun_news(2, 5, 0);
 
require PUN_ROOT.'footer.php';

Thanks in advance
Bingiman

Re: Mini News

Dam deceptively names truncate variable smile Try this?

###############
# Near top
###############
function pun_news($fid='', $show=15, $truncate=250)

###############
# Near Middle
###############
        // Display first paragraph only (comment out next four lines to turn off)
        if ($truncate)
        {
            $paragraph = '';
            for ($numchar=0; $numchar<$truncate; $numchar++)
            {
                if (isset($cur_post['message'][$numchar]))
                    $paragraph .= $cur_post['message'][$numchar];
                else break;
            }
            $paragraph .= ' …';
            $cur_post['message'] = $paragraph;
        }

###############
# Bottom top
###############
echo pun_news(2, 5, 250);

There you go, now it truncates at the char. (Please not that if it truncates away the end tag of a BBcode statement, you might get into trouble tongue)

echo "deadram"; echo; fortune;

Re: Mini News

Thank you very, very much. I really appreciate this. It works great now.

Cheers!
Bingiman big_smile

Re: Mini News

Can I ask you another question. I added a read more icon to my news index but I wanted to know if there is a way I can have it so that if there isn't any more text in that particular post to read then the read more button remains hidden.

Thanks
Bingiman

15 (edited by quaker 2007-03-01 03:22)

Re: Mini News

this is a mini new system that i used on one of my sites...
http://bunpai.com
take this code and place it anywhere you want the news item to showup...

what i did was create a folder called user under include
include/user
i named this portalnews.php
so it is like this include/user/portalnews.php

then i placed this code in the main.tpl where i want the item to show up

<div id="right">
            <div class="leftcol">
                <p><pun_include "portalnews.php"></p>
                <p></p>
            </div>
<?php
$newsid = '1'; // Forum id to fetch the news from ( only supports 1 forum id )
$newsdisplay = '5'; // Number of news to display.

?>

<?php
require_once PUN_ROOT.'include/parser.php';

?>




<?
$result = $db->query('SELECT t.id, t.subject, t.num_replies, t.last_post, t.last_post_id, t.last_poster, t.num_views, t.forum_id, p.poster, p.poster_id, p.message, p.hide_smilies, p.posted, g.g_title, f.forum_name FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON p.topic_id=t.id AND p.posted=t.posted INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id WHERE t.forum_id='.$newsid.' AND t.moved_to IS NULL AND f.redirect_url IS NULL ORDER BY t.posted DESC LIMIT '.$newsdisplay) or error('Unable to fetch announcements', __FILE__, __LINE__, $db->error());

if ($db->num_rows($result))
                    {
                            while($cur_post = $db->fetch_assoc($result))
                            {
                                    $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
?>

<?
echo "\t\t\t\t\t\t\t".' <h2><span>'.pun_htmlspecialchars($cur_post['subject']).'</span></h2>'."\n";
?>


<ul>

<?php echo $cur_post['message']."\n" ?><br />


<?
echo "\t\t\t\t\t\t\t".'<a style="text-decoration: none" href="viewtopic.php?id='.$cur_post['id'].'" class="username">'.pun_htmlspecialchars($lang_portal['Visit_Topic']).'</a>'."\n";
?>

<div style="text-align: right">

<?
echo "\t\t\t\t\t\t\t".'<p class="date">Posted by: <a style="text-decoration: none" href="profile.php?id='.$cur_post['poster_id'].'" class="username">'.pun_htmlspecialchars($cur_post['poster']).'</a> <a href="about.php"> | Read more</a> <img src="images/comment.gif" alt="" />  '.pun_htmlspecialchars($lang_portal['Comments']).': '.pun_htmlspecialchars($cur_post['num_replies']).' <a href="#">Comments (3)</a> <img src="images/timeicon.gif" alt="" /> '.pun_htmlspecialchars($lang_portal['Views']).': '.pun_htmlspecialchars($cur_post['num_views']).'</span></p><br />'."\n";
?>

</div>
</ul>


<?
}
 }
else
{

 }    
?>
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: Mini News

Thank you very much for that. I still need to figure out the answer to my previous question above your last post.:(