MyBB Community Forums

Full Version: Displaying News on your homepage
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
(2009-02-09, 10:56 PM)ak47 Wrote: [ -> ]Tried but nothing show up.

Can you please provide me code for news.php & newsheader.php ll be a great help.


EDIT: i re-created file now i get this error
MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
    1146 - Table 'kdbb.mybb_mybb_threads' doesn't exist
Query:
    SELECT * FROM mybb_mybb_threads WHERE fid='2' ORDER BY tid DESC LIMIT 5

Remove the TABLE_PREFIX if you're using 1.4.x
Thanks Lee problem is solved. Smile
Just out of interest, how much resources/strain/cpu usage causes a script like this on the server/mysql database? For example, I'm currently running two websites which pull news posts from the same forum database, plus a bunch of webpages which all pull posts from separate (hidden) forums which function as sort of a "content management system" for those particular pages. Is it like, whenever somebody (a person, a bot/crawler?) visits the main page the script basically searches the complete database for a certain string so it's equivalent to a manual search by someone within the forum per visitor? Will lots of visitors cause issues like too many connections to the database (don't know if that's visitor based or mysql user based?)?

Just a general interest and something I might have to keep in mind when the website expands.
eum , i think it all depends from your cpu processor
i got a website whit 48 pages and it use just 1% cpu (not even 1%)

then i got a same kind of you whit the news plugin on my other domain and the average use is 3%

Server Load Averages 2.89, 5.52
Server Uptime 1 day, 10:59

its a cpanel account on a other server , so i am not the only 1 that use the cpu

probaly you need to count that it will take about the 3% - 5% cpu per 200 visitors (at the same time)

the database is visitor related , every visitor opens a new conection to the database (it let execure the script) and shows the value's and then close the script again to prevent to many conections

to make it short
if a visitor opens a website , then it create a mysql conection (same as the forum does) and it close it after it got the data it needed
so if you got 1000 visitors that opens the website at the same time , then you get conection errors , if you get only 10 visitors at the same time then you dont get any trouble (depends how many conections you can get at the same time)

then the size of your db , if it is realy big then it takes a lot of time , if it is small then it doesnt give a single problem

i hope this could help you a bit Confused

Greets From The Crasher
Yes, that helped, thanks Crasher Smile
(2009-01-31, 12:25 PM)MrD. Wrote: [ -> ]Oops, I had search and subject the wrong way around (that'll teach me to read the PHP documentation better):

$subject = str_replace('[ARMA]', '', $row['subject']);
Today I noticed something, the news part that uses the above code for some reason ignores the 6 post limit, it only shows 4 posts, while other parts on the website which also pull posts (without any str_replace) do recognize the 6 posts limit.

Like on my website, in the main frame there are news posts (which use the [ARMA] tag), those only show 4 posts (out of lots more), to the right I have an articles list (pulling from a different forum id using the original code), that list does show more than 4 items, same with a website news part which is above that, it shows the 6 items too.

So it looks like the customized code only displays a maximum of 4 posts.
Love this script but I am looking for one that would post only the heading or subject of the latest post from each forum to my homepage instead of displaying the whole thread.
For example if I have a forum name Events and there's a new post Dance tonight 5PM. It would display like this

Events: Dance tonight 5PM
Rants: I love my kids
Recipes: Fish Fry

and so on.
(2009-03-01, 05:47 PM)zoog Wrote: [ -> ]
(2009-01-31, 12:25 PM)MrD. Wrote: [ -> ]Oops, I had search and subject the wrong way around (that'll teach me to read the PHP documentation better):

$subject = str_replace('[ARMA]', '', $row['subject']);
Today I noticed something, the news part that uses the above code for some reason ignores the 6 post limit, it only shows 4 posts, while other parts on the website which also pull posts (without any str_replace) do recognize the 6 posts limit.

Like on my website, in the main frame there are news posts (which use the [ARMA] tag), those only show 4 posts (out of lots more), to the right I have an articles list (pulling from a different forum id using the original code), that list does show more than 4 items, same with a website news part which is above that, it shows the 6 items too.

So it looks like the customized code only displays a maximum of 4 posts.

I found out what the problem is. Using the "tag system" it searches for the first 6 threads, and displays all the "tagged" threads from those six. So for example, when 2 of the first 6 threads have the [ARMA] tag, there are only 2 items shown on the frontpage. When 5 of the 6 first threads have the [ARMA] tag, 5 posts are shown on the front page. So it basicly counts all the posts and then picks the ones to show. When I think about it this is pretty logical. Any easy way to circumvent this?



Quote:Love this script but I am looking for one that would post only the heading or subject of the latest post from each forum to my homepage instead of displaying the whole thread.
For example if I have a forum name Events and there's a new post Dance tonight 5PM.

What I think you should do is edit the echo part of the script:

change this:
            echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a> - 
                Posted: {$date} {$time} by <a href=\"{$forumpath}member.php?action=profile&uid={$row2['uid']}\">{$row2['username']}</a><br />");
            echo("{$message}<br /><br />");
            echo("Replies (<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['replies']}

into this:
echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a>

So you have something like this:

  
<?php

    $fid = 2;
    $limit = 1;
    $forumpath = 'forum/';

    chdir($forumpath);
    define("IN_MYBB", 1);
    require('./global.php');
    require_once MYBB_ROOT."inc/class_parser.php";
    $parser = new postParser;
    chdir('../');
?>
<?php
    
    $query = $db->simple_select('threads', '*', "fid='2,3,4,5,6,<all forum numbers you want>' ORDER BY tid DESC LIMIT {$limit}");
    if($db->num_rows($query) > 0)
    {
        while($row = $db->fetch_array($query))
        {
            $query2 = $db->simple_select('posts', '*', "pid='{$row['firstpost']}'");
            $row2 = $db->fetch_array($query2);
            
            $date = my_date($mybb->settings['dateformat'], $row2['dateline'], "", 1);
            $time = my_date($mybb->settings['timeformat'], $row2['dateline'], "", 1);

            $options = array(
                            'allow_html' => '1', 
                            'filter_badwords' => '1', 
                            'allow_mycode' => '1', 
                            'allow_smilies' => '1', 
                            'nl2br' => '1', 
                            'me_username' => '1'
                            );
            $message = $parser->parse_message($row2['message'], $options);
	    echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a><br>");
	    }
    }
    else
    {
        echo 'Nothing to display.';
    }

?>
Thankz Its very good
This works perfectly, the only question i have

How do i get attachments to show?

Thank You Kindly
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33