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
1) Using the string that is trimmed down from the full post, you should be able to use strrpos to find the last space in the string and then substr it to that position which will stop it cutting off words.

Something like:
$message = $parser->parse_message($row2['message'], $options);
// Not sure if this is safe, of if you should make sure strlen($message) >= <your max message length> first
$spacePos = strrpos($message, ' ', <your max message length>);
if($spacePos === true)
	$message = substr($message, 0, $spacePos);

2) This should show how to do pagination, it may well need a touch of updating for 1.4.

3) This is just a general PHP question, that URL is actually malformed, but checking out the GET section here should point you in the right direction.
Is it possible to display news from multiple forums.

For example if you have a forum for each game on a game site which is used to show announcements on the main website, how would you get them to display in order and show them on the website.

I am also trying to limit the amount of characters on the front of the news page and am having trouble in doing so also.

Thanks MrD. Big Grin
Ok, I'm going to be totally honest with everyone here. I made this thread over 2 years ago, I haven't had a MyBB forum of my own, or even a test board for well over a year yet I have tried to do my best to help you all out based only on my knowledge of PHP. All the code I have posted in this thread since around June 2008 has been totally un-tested and pieced together in my head, and for the most part it worked.

Now though I am starting to get really tired of it, I don't mean you to take this the wrong way and think that you are annoying me with your questions, you're not. What I'm tired of is working out and posting totally un-tested code and then having someone else test it for me.

Yes, I could install another test board to test these things out, but to be frank, I'm not going to do that just so I can post in this thread.

In short, after this post do not expect me to reply with an answer to your question, especially if that question has already been answered in this thread. I am far less tolerant for this sort of thing that I was years ago, I have lived and worked in a professional environment where doing your own research and solving your own problems was paramount. I don't care if you don't want to read through 302 posts to find the answer you're looking for, but if you expect me to do that for you then you are sadly mistaken.

These are your forums, not mine. You have taken the responsibility to run them, not me. Part of that responsibility involves learning about your website and how to change it, I learnt PHP in the first place from running forums. If you don't want to do this yourself, then find someone who will and let them do it for you. Do not expect handouts from other people, and only ask questions if you have exhausted all other options; search, read, experiment then post a question stating everything you have done yourself to try and overcome the problem. That is the professional attitude to problem solving, and it is that which gets you the respect of the person who answers your question, because you have already done all the mundane leg-work they would have had to go through with you, and I'm sure they appreciate it; I know I do.

It's all right to be new and inexperienced, everyone is at some point. But please, don't stay like that. I have said this before and I will say it again, I have no problem helping people who want to learn, it's the people who just expect hand-outs time after time that get to me. They get to everyone, and eventually we all reach a point where we just have to say "enough is enough"; this is that point for me with this thread.

I wish you luck with your forums. Don't be a newbie forever Big Grin



Now on to my actual reply... goombastic, I am 99% sure your first question has already been answered in this thread, if you read my large rant above you will know what I am going to do to help you find that out, and that is nothing. Have fun digging, come back to me if I am wrong and you find nothing.

As for your point about character limiting, I am not psychic. To my knowledge the code I posted above your post should work, but is totally untested. What is your code for your character limiting, and in what way does it not work?
Is there a way to make this work like you put {$news} into a template.
A MyBB template? You can probably do that with a plugin, but I have no idea how the plugin system works with regard to creating new template variables.
I get this error in a little mybb box thing.


MyBB has experienced an internal SQL error and cannot continue.

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

I can see what's wrong obviously but i don't know what to do or anything.

New to php so any errors prove difficult.


EDIT: Fixed, Working. Oh and forgot to say Thanks, Thanks. Big Grin
How can i change this:
     $fid = 2; 

So, it can be like 2, 3 ,4, 5 or whatever, so i can list all forums.


Or some other way i can make it show all forums.
(2009-06-04, 02:51 PM)zoog Wrote: [ -> ]Anyone knows what I should change in the code in order to display only one specific post (id)? Smile

I'm still (now desperately) searching for a way to use this news script to only show 1 specific post on my frontpage, I need this for managing static content for my website.

Right now I have several static pages with the current script, every static page points to a different forum id. Inside these different (hidden) forum id's is 1 post. But for every static page I need to create a new (hidden) subforum with just 1 post which shows as static content on the front end for a particular page.

Since I need more and more static pages I need to find a way to simply pull a single post id instead of a forum id.
It would simply be:
$query = $db->simple_select('posts', '*', "pid='<YOUR ID HERE>'");
Thanks, I guess I tried that but only with query number 2. Now I changed them both (query 1 and 2) and it works like a charm, thanks mate Smile
You should only need one query to be honest since what the news code does it find a thread, then get all posts in that thread. Since you only want a single post, you should be able to do it like this:

<?php
    
    $query = $db->simple_select('posts', '*', "pid='<YOUR ID HERE>'");
    if($row = $db->fetch_array($query))
    { 
		$date = my_date($mybb->settings['dateformat'], $row['dateline'], "", 1);
		$time = my_date($mybb->settings['timeformat'], $row['dateline'], "", 1);

		$options = array(
						'allow_html' => 'no', 
						'filter_badwords' => 'yes', 
						'allow_mycode' => 'yes', 
						'allow_smilies' => 'yes', 
						'nl2br' => 'yes', 
						'me_username' => 'yes'
						);
		$message = $parser->parse_message($row['message'], $options);
		
		echo("<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['subject']}</a> - 
			Posted: {$date} {$time} by <a href=\"{$forumpath}member.php?action=profile&uid={$row['uid']}\">{$row['username']}</a><br />");
		echo("{$message}<br /><br />");
		echo("Replies (<a href=\"{$forumpath}showthread.php?tid={$row['tid']}\">{$row['replies']}</a>)<br /><hr />");
}
    else
    {
        echo 'Nothing to display.';
    }

?>
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