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-01-30, 11:56 PM)TomL Wrote: [ -> ]Good job, MrD.Smile

Thanks, I just checked when I made this thread out of curiosity. It was a long time ago (approx. 1 Year, 4 Months). I also notice that my post count has dropped by ~200 posts, I guess the last one to post contest got moved.
Out of curiosity, How can I get maybe 30 characters of the announcement in my index.html without avatar, number of replies or views?

http://www.passionateprayer.net

where it says news, in that small space. Then with a link that says [Read More] that leads to the thread
(2009-01-30, 11:56 PM)TomL Wrote: [ -> ]
(2009-01-30, 11:51 PM)Craigw Wrote: [ -> ]i know this code isnt that great, but it works for me.

if($mybb->user['avatar'] > "")
{
echo "<a href='/member.php?action=profile&uid=". $mybb->user['uid']."'><img style='border: none;' src='".$mybb->user['avatar']."'/></a><br /><br />";
}

basically it shows the users avatar only when one exists (stops image not found error.)
The
if($mybb->user['avatar'] > "")
should actually be
if($mybb->user['avatar'] != "")
since it makes no sense to check if it's greater than(>) "", as it's not a valid check. You can leave it how you have it though if you want, just saying..

yea, up until recently i didnt know i could use that operator in php, it works, thats all that matters Toungue
(2009-01-30, 10:33 PM)zoog Wrote: [ -> ]
(2009-01-30, 07:37 PM)MrD. Wrote: [ -> ]This will only work properly in PHP 5, since it needs to do a search for the whole needle string:
if(strpos($whateverTheSubjectVarIsCalled, '*[ARMA]*') !== FALSE)
{
// echo the post
}

Thanks man. Thanks for your continues support on this script.

I'm going to try it out tomorrow, I first need to get some sleep Smile
I've been trying different things for a while now but I'm not sure if I'm doing it correctly (server is running php5).

I assume that the $whateverTheSubjectVarIsCalled must be changed to $subject. At least, that's what I did (I did some searching in the MySQL database and as a noob I think it's called 'subject'). Now I've tried to put the new line of code in the script (on any logical location I could think of) but it either gives me all posts, or it gives me the "Nothing to display" message. I tried to either use the 'FALSE' or 'TRUE' command, without any difference.

I'm sure I'm doing something wrong (I'm simply trying to understand the script without any programming experience). Where needs the new code to be placed?

The current code for the script is this:

<?php

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

    chdir($forumpath);
    define("IN_MYBB", 1);
    require('./global.php');
    require_once MYBB_ROOT."inc/class_parser.php";
    $parser = new postParser;
    chdir('../');
?>
  <span class="forumtext">
  <?php
    
    $query = $db->simple_select('threads', '*', "fid='2' 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>
            {$date} {$time} door <a href=\"{$forumpath}member.php?action=profile&uid={$row2['uid']}\">{$row2['username']}</a><br><br><br>");
        echo("{$message}<br><br><br>");
            echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['replies']} Replies</a><br><br><br><hr />");
        }
    }
    else
    {
        echo 'Nothing to display.';
    }

?>

Any help is greatly appreciated Blush
If it's going to work, this should do it:

<?php

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

	chdir($forumpath);
	define("IN_MYBB", 1);
	require('./global.php');
	require_once MYBB_ROOT."inc/class_parser.php";
	$parser = new postParser;
	chdir('../');
?>

<span class="forumtext">

<?php

$outputtedCount = 0;
$query = $db->simple_select('threads', '*', "fid='2' ORDER BY tid DESC LIMIT {$limit}");
if($db->num_rows($query) > 0)
{
	while($row = $db->fetch_array($query))
	{
		if(strpos($row['subject'], '*[ARMA]*') !== FALSE)
		{
			$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>
			{$date} {$time} door <a href=\"{$forumpath}member.php?action=profile&uid={$row2['uid']}\">{$row2['username']}</a><br><br><br>");
			echo("{$message}<br><br><br>");
			echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['replies']} Replies</a><br><br><br><hr />");
			
			++$outputtedCount;
		}
	}
}
if($outputtedCount == 0)
{
	echo 'Nothing to display.';
}
?>
Thanks, thanks so much Big Grin First the new code didn't work, but then I removed both *'s in the following line:

if(strpos($row['subject'], '*[ARMA]*') !== FALSE)


so that it would be:

if(strpos($row['subject'], '[ARMA]') !== FALSE)


and it works!

Thanks MrD. Heart
Oh right, I thought the *'s were part of the string you wanted to look for. Guess not.
I see Smile I thought it was part of the necessary code.

One last question, and I do understand if you'll skip this one, but would it be easy to modify one more thing. So that the subject line that is posted doesn't show the [ARMA] part. So in example in the forum the subject is like "[ARMA] New release date", while in the output in the news script on the website the post shows like "New release date". So basicly removing the pre-defined tag from the echo part?
Change:
echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a><br>

To:
$subject = str_replace($row['subject'], '', '[ARMA]');
echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$subject}</a><br>
Thanks. Unfortunately it does the opposite. It removes the rest of the subject and places only the [ARMA] tag in the output on the website. I also tried to put the [ARMA] tag into the first ' ' but that makes it remove the subject line completely.
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