Skip to:
Content
Pages
Categories
Search
Top
Bottom

bbpress plugin – templates in bbpress folder


  • Anointed
    Moderator

    @anointed

    I don’t want to hijack the thread where JJJ and I were talking about the template locations filling up my theme root, so here is a new post.

    I was playing around with an idea, and before I go to far with it, I was curious what you think.

    You had mentioned that this type of system was expressly forbidden by wp, due to having to search all folders for files before proceeding. That would be a nightmare, but here I am defining the folders up front, so it ‘should’ be just as fast, though I am unsure of how to bench test it.

    If we could get a system in place like this, then it would clean up the theme area considerably.

    I am using the same logic on a number of client sites and it works perfectly, though they are not using bbpress or buddypress. I simply use it for my own custom post-types.

    example:

    public function template_include( $template ) {
    if ( get_query_var('post_type') == $this->post_type ) {

    if ( is_single() ) {
    if ( $single = locate_template( array( $this->post_type.'/single.php') ) )
    return $single;
    }
    if ( is_paged() ) {
    if ($paged = locate_template( array( $this->post_type.'/archive.php') ) )
    return $paged;
    }
    else { // loop
    return locate_template( array(
    $this->post_type . '/index.php',
    $this->post_type . '.php',
    'index.php'
    ));
    }

    }
    return $template;
    }

    This would completely change the structure of bbpress template names, but could potentially allow me to store everything inside 3 folders ‘forums/topics/replies’.

    I’m sure there would be much more to it than that….

    What do you think of this type of approach?

    *right now it is quite generic and would effect all custom post_types, which would not be good. Changing to be bbpress specific would prob just be a matter of defining types in the array vs. all

    I’m really asking because even though I know I could get this to work, I am quite curious how this would end up effecting buddypress when combined with bbpress.

    Would a system like this be a deal breaker?

    Good idea or bad?

Viewing 3 replies - 1 through 3 (of 3 total)

  • John James Jacoby
    Keymaster

    @johnjamesjacoby

    I don’t think using something like that is a bad idea at all. I’d reverse the logic a little bit, and predefine the template hierarchies for the single, archive and else scenarios, and allow them to cascade as needed from several locations.

    The long term performance issue is: the more possible files it looks for, the more file_exists() checks PHP runs, which is more access to the file system, and when those get into the hundreds of requests is going to be a pain point. Like many things it’s a balance between flexibility and performance, and finding the best times to make those compromises.

    I could see something like this happening for BuddyPress 1.4, and possibly for bbPress 2.1. I’ll play with the idea after Beta 2 drops to see if it’s worth making the adjustment. It’s a bit late in the beta phase to make a change this large, but if the overall benefit is worth the change and it doesn’t break any existing installs, then it’s a possibility.


    Anointed
    Moderator

    @anointed

    My concept was to have template files defined just as directly as native wp does it, only using a folder system instead, thus keeping file_exists() to the same level.

    As you can tell by the snippet, it is very basic. It works perfectly for standard post_types, as there are only a few template files to define.

    A system like bbpress and buddypress is much more involved, thus requiring many new rules. Unfortunately I don’t know either system well enough yet to come up with a rock solid routing platform. I guess by the time I finish with bbpress that I will then have a strong enough understanding to pull this off.

    Theoretically it should not break existing installs, as nothing really changes other than file locations, which would be defined anyhow. When plugins come into play it could become an entirely different situation though.

    If you don’t beat me to it, I will try to come up with a complete system for bbpress when I finish my project site.

    *I don’t think anything would actually have to change within bbpress itself. A custom function would simply reroute the wp template_include() to the new locations. But then again, I am sure you are aware of many other possible problems than I am.

    Glad to hear you think it may be feasible.


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    The file_exists() checks increase exponentially with each miss in the hierarchy when a file isn’t in the first/second/third position, etc… So depending on the configurations that other theme developers would choose to adopt for their needs, it may or may not be an issue.

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.