MyBB Community Forums

Full Version: Get and display contents from database
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey,

I know a lot about PHP, but I know next to nothing about MyBB, coding wise. What I want to do is get the latest "stickied" wordpress blog post and display the contents on the forum inside the header, but only if there are any stickied wordpress posts. I could code this myself, but how would I be best advised to make a system like this?

Thanks.
When you say - display the contents on the forum inside the header - I guess you're meaning a coloured bar like the ones here?

You will probably need to code a plugin, which might look something like this:

if(THIS_SCRIPT == "index.php")
{
	$plugins->add_hook("global_start", "announce_start");
}

function announce_start()
{
	global $db, $templates;

	$query = $db->query("SELECT * FROM wordpress_post_table WHERE << where conditions here >>");
	if($db->num_rows($query))
	{
		// Only continue if we have a stickied wordpress post
		$headers = '';
		while($post = $db->fetch_array($query))
		{
			$post_time = my_date($mybb->settings['dateformat'], $post['timestamp_here']).", ".my_date($mybb->settings['timeformat'], $post['timestamp_here']);
			$headers .= '<div class="header">'.htmlspecialchars_uni($post['title_of_post']).' ('.$post_time.')</div>';
		}

		// Alter header template to put in our headers...
		$templates->cache['header'] = str_replace("<navigation>", $headers."<br /><navigation>", $templates->cache['header']);
	}
}

Or something to that effect. Have a look at the "Hello World" sample plugin that comes with MyBB and have a flick through the [Wiki: Authoring_Plugins] (Broken link, head over to docs.mybb.com instead) to pull it altogether. Smile