WordPress Blog Posts within Moodle Front Page

Moodle+WordpressIf you are not already reading this there then if you visit http://matc-online.co.uk/ you will see that the site is running Moodle but there is a WordPress Blog contained on the front page.

The post explains why and how…

Firstly WordPress is just very good for blogging. Yes you can blog within Moodle but I would like to use the a mobile app and/or desktop apps to write posts and WordPress has these already built.

For this to work there is an instance of WordPress contained within a sub-directory of Moodle, visit http://matc-online.co.uk/wordpress to just see the Blog without Moodle.

In theory to have WordPress in another site you just need to include the following code

define('WP_USE_THEMES', false);

followed by the standard WordPress Loop

if(have_posts()) : while(have_posts()) : the_post();
...display post...

Under normal circumstances that would work but Moodle and WordPress both use functions with the same name and in PHP you cannot redeclare a function. I could change some of the core code for either to fix this but this would break everytime either is updated

To get this to work without changing any core code I created a page outside of Moodle to fetch the postsusing the previously described code. Then in my theme modified the /layout/frontpage.php to include the output from that page.

echo file_get_contents('http://matc-online.co.uk/extra/wordpressfetch.php');

To finish off insert the css from the WordPress theme in the frontpage head section just before

echo $OUTPUT->standard_head_html()

Leave a Reply

Your email address will not be published. Required fields are marked *