3. A forum in a blog ?

 

At first it was all good, we had our users who were able to login, viewing the site, make comments and create posts on the forum. The next step was to make sure that the forum was surrounded by our wordpress theme.

When viewing our site you saw the nice header, a sidebar and a footer navigation designed for a flawless ux. If you visited the forum all of this was gone; the forum goes fullscreen and al your handy navigation was “lost”.

 

 

A solution was needed and a few tricks were able to provide this.

WordPress point of view

WordPress consist of pages with a certain content. This content could be standard text, images, embedded video’s and even php if necessary.

Baddest idea:
Using a php plugin which allows php written in a post. Logically, copy-pasting the content of our index.php doesn’t work.

Badder idea:
Using a combination of wp-load.php and a new php file with the following content:

  1. <?php
  2. require_once(dirname(__FILE__) . '/wp-load.php');
  3. get_header();
  4. ?>
  5. <head>
  6. <style type="text/css">
  7. #content-body {
  8. display:none !important;
  9. }
  10.  
  11. #content_next_event {
  12. display:none !important;
  13. }
  14.  
  15. #test {
  16. display:inline-block;
  17. margin-top: 10px;
  18. padding-bottom: 10px;
  19. background: #FFFFFF;
  20. height: auto !important;
  21. border-bottom: 20px solid #EDEDED;
  22.  
  23. }
  24. </style>
  25. <script language="JavaScript">
  26. <!--
  27. function calcHeight()
  28. {
  29. //find the height of the internal page
  30. var the_height=
  31. document.getElementById('the_iframe').contentWindow.
  32. document.body.scrollHeight;
  33.  
  34. //change the height of the iframe
  35. document.getElementById('the_iframe').height=
  36. the_height;
  37. }
  38. //-->
  39. </script>
  40.  
  41. </head>
  42. <div id="the_iframe">
  43. <?php
  44. $a = file_get_contents('/forum/index.php');
  45. echo ($a);
  46. ?>
  47. </div>
  48.  
  49. <?php
  50. get_footer();
  51. ?>

Although the function “file_get_contents” does give me a forum inside wordpress, the functionality is zero.

Bad idea:
Using the iframe plugin for wordpress. I’m not beginning to discuss the advantage/disadvantage of an iframe, but this worked for me. Wel… at least for 70%

the forum is loaded in an iframe (with the setting   [iframe same_height_as="content"]) but this can lead to some “funky” results. Loading a topic halfway and then rendering the page with a height of that topic but completely blank, not adjusting heights when opening attachments etc.

Not to mention the problem you’ll have with Google Analytics of not indexing.

We skip the good idea and go straight to the

Best idea:
Instead of bringing a forum to wordpress, why not do it the other way ?

4. A blog in a forum ?

Well, not fully a blog but only the header and the footer. But how do we achieve this ? By changing a few files in Smf.

in /forum:

index.php

add the following line above “$forum_version = ‘<your smf version’;>

require_once('/path/to/wp-load.php');

Now wait, when looking for this stuff, wordpress tells me I’ve to use:

<?php
require('/the/path/to/your/wp-blog-header.php');
?>

What’s the difference ? In this case when using wp-blog-header.php, I received false 404 headers on my external page.

A quick fix is either using wp-load.php or … deconstruct it into its component functions, excluding the bad ones.

WordPress is instantiated by calling the WP class.  Use the following: require_once(“/wp-config.php”);
$wp->init();
$wp->parse_request();
$wp->query_posts();
$wp->register_globals();
$wp->send_headers();

From the documentation:
init() — set up the current user.
parse_request() — Parse request to find correct WordPress query.
query_posts() — Set up the Loop based on the query variables.
register_globals() — Set up the WordPress Globals.
send_headers() — Sets the X-Pingback header, 404 status (if 404), Content-type. If showing a feed, it will also send last-modified, etag, and 304 status if needed.

And obviously, we’re leaving out handle_404().
handle_404() — Issue a 404 if a request doesn’t match any posts and doesn’t match any object (e.g. an existing-but-empty category, tag, author) and a 404 was not already issued, and if the request was not a search or the homepage. Otherwise, issue a 200.

Now, our page work as expected.

In /forum/Themes/<yourTheme>/

index.template.php

Look for “function template_html_above()” and add above:

require_once('/path/to/your/wordpress/theme/header.php');

Score ! We now have a fully functional forum with a wordpress header. Ofcourse we need to do alot of css styling to make sure that everything is proper in place. (Not to mention to remove the second doctype which is located in index.template.php)

Additional problem:

Buddypress was still giving some small issues.

The BuddyPress “rewriting” system is quite intricate (it’s called a “URI catcher”), in this case it breaks the request down and searches for an exact match in page slugs to provide the final URL, and the page slug in this case is register.

because of this rewrite rules. It changes ”/forum/index.php?action=register” into “/register”, giving an error 404

So how to fix this ?

/wp-config.php:
at the bottom ad the following

define( 'BP_SKIP_REGISTRATION_REDIRECT', true );

/wp-content/plugins/bus/buddypress/bp-members/bp-members-signup.php:
paste the following at the end of the file, overwriting the excisting  function

function bp_core_wpsignup_redirect() {
	$action = !empty( $_GET['action'] ) ? $_GET['action'] : '';
 
	// Not at the WP core signup page and action is not register
	if ( false === strpos( $_SERVER['SCRIPT_NAME'], 'wp-signup.php' ) && ( 'register' != $action ) )
		return;
 
	if ( defined( 'BP_SKIP_REGISTRATION_REDIRECT' ) and BP_SKIP_REGISTRATION_REDIRECT ) return;
	// Redirect to sign-up page
	if ( locate_template( array( 'registration/register.php' ), false ) || locate_template( array( 'register.php' ), false ) )
		bp_core_redirect( bp_get_signup_page() );
}
//add_action( 'bp_init', 'bp_core_wpsignup_redirect' );

 

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 
© 2012 Ceekes boarderline Suffusion theme by Sayontan Sinha