MyBB Community Forums

Full Version: WordPress
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys I'm trying to find a way to add a recent posts widget to my WordPress website. I've tried the plugin MyBB Cross-Postalicious it doesn't seem to work for me.

I've tried adding a sidebar recent posts code from a theme doesn't seem to work.
Hmm I am writing an integration for WP -> WP and make Wp posts from Mybb I could probably add this to it if there is enough demand.

One quick and dirty way to do this would be to use the current latest posts and use buffering to output this to a variable and then push that variable to output to a .html page then you could just include that HTML page into WP
(2013-08-15, 01:13 AM)Dannymh Wrote: [ -> ]Hmm I am writing an integration for WP -> WP and make Wp posts from Mybb I could probably add this to it if there is enough demand.

One quick and dirty way to do this would be to use the current latest posts and use buffering to output this to a variable and then push that variable to output to a .html page then you could just include that HTML page into WP

I can't wait for the release then!, Will be looking forward to it. Yeah, I was trying to get the html, but I just couldn't and I don't know how to do what you just said >.>
I can show you how to get the header and footer in HTML form from wordpress.

I have a page called "HTML_gen.php" which I call via a Cron job twice a day

require( '/home/dev/public_html/wordpress/wp-load.php' );

#### Generate the Header ###
ob_start();
get_header();
$header = ob_get_contents();
ob_end_clean();


I then do a whole lot of cleaning to remove everything from <!doctype> to the body tag because I use mybb headerinclude and include only what I need from there in the header.

So my cleaning looks like
$header = preg_replace('/<!*DOCTYPE(.*?)<\/head>/si', "",$header);
$header = preg_replace('/<body(.*?)>/si', "",$header);

I also have advertising which I generate out of mybb and pull into WP, however when I generate the page I replace this with the myadvertisement code as such

$header = preg_replace('/<!--[ ]*Start[ ]*Advertisement[ ]*1[ ]*-->(.*?)<!--[ ]*end[ ]*advertisement[ ]*1[ ]*-->/si', '{myadvertisements[zone_1]}', $header);

I then do a whole lot of replacements to prepend all of the wordpress CSS classes with "wp" so that there is no conflict with my mybb style and put it into an HTML file


$patterns[0] = '/class="/';
$patterns[1] = '/id="/';
$patterns[2] = "/class='/";
$replacements = array();
$replacements[2] = 'class="wp';
$replacements[1] = 'id="wp';
$replacements[0] = "class='wp";

$header = preg_replace($patterns, $replacements, $header);


$header = preg_replace('/class="wpcat-item cat/', 'class="wpcat-item wpcat', $header);

$header .= '<div id="wpcontent">';
file_put_contents("/home/dev/public_html/wodpress/wp-content/html/header.html", $header);


I then do the same for the footer

#### Generate the sidebar #####

ob_start();
dynamic_sidebar('right-sidebar');
$sidebar = ob_get_contents();
ob_end_clean();

$patterns[0] = '/class="/';
$patterns[1] = '/id="/';
$patterns[2] = "/class='/";
$replacements = array();
$replacements[2] = 'class="wp';
$replacements[1] = 'id="wp';
$replacements[0] = "class='wp";
$footer = preg_replace('/<!--[ ]*Start[ ]*Advertisement[ ]*1[ ]*-->(.*?)<!--[ ]*end[ ]*advertisement[ ]*6[ ]*-->/si', '{myadvertisements[zone_6]}', $footer);
$footer = preg_replace('/<!--[ ]*Start[ ]*Advertisement[ ]*1[ ]*-->(.*?)<!--[ ]*end[ ]*advertisement[ ]*5[ ]*-->/si', '{myadvertisements[zone_5]}', $footer);
$footer = preg_replace('/<!--[ ]*Start[ ]*Advertisement[ ]*1[ ]*-->(.*?)<!--[ ]*end[ ]*advertisement[ ]*6[ ]*-->/si', '{myadvertisements[zone_6]}', $footer);
$footer = preg_replace('/<!--[ ]*Start[ ]*Advertisement[ ]*1[ ]*-->(.*?)<!--[ ]*end[ ]*advertisement[ ]*4[ ]*-->/si', '{myadvertisements[zone_4]}', $footer);
$footer = preg_replace('/<!--[ ]*Start[ ]*Advertisement[ ]*1[ ]*-->(.*?)<!--[ ]*end[ ]*advertisement[ ]*9[ ]*-->/si', '{myadvertisements[zone_9]}', $footer);
$sidebar = preg_replace($patterns, $replacements, $sidebar);
$sidebar = str_replace('href="#', 'href="#wp', $sidebar);
file_put_contents("/home/dev/public_html/wordpress/wp-content/html/sidebar.html", $sidebar);

I need to clean that up a bit so that it just does a preg_match to possible make it faster, but to be honest it really doesn't impact load as it is only loaded twice a day.

The reason I replace the advert code, is this way mybb can process the adverts on each page load so I am not always loading the same one.

Now in mybb I have a plugin which simply does the following

$plugins->add_hook('global_end', 'swmc_header');

function swmc_header()	{
	global $header,$footer;

	//file_get_contents('http://www.silvertails.net/content/wp-content/silvertails_html/header.html');
	$header = str_replace('{wordpress_header}', file_get_contents('/home/dev/public_html/wordpress/wp-content/html/header.html'), $header);
	$footer = str_replace('{wordpress_sidebar}', file_get_contents('/home/dev/public_html/wordpress/wp-content/html/sidebar.html'), $footer);

	return $page;
}

Then in your templates wherever you want the header and sidebar to appear just put

{wordpress_header}
{wordpress_sidebar}

You can do the same with the footer by just calling
ob_start();
get_footer();
$footer = ob_get_contents();
ob_end_clean();

And writing that out to a footer.html file using the methods above and calling it the same way.

You would have to do any cleaning.

I then grabbed the CSS file from wordpress that I use and changed all of the classes to start with wp and added that to my mybb theme. With mine I had to do some JS transformations because of some ore complex code, but that wont be needed in most cases.

That way you get easy and fast visual integration of your site with very few overheads. I don't love the fact I have to use file_get_contents and do a replace on global_end but it seems to be pretty fast. Technically readfile() is actually faster than file_get_contents but I had real issues with trying to get rid of the byte count from displaying.

Hope this helps. I have one person beta testing the Discussbot integration at the moment if you want to test it on a test site let me know and I will pass the code over
I see, thank you.