Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/13/2013 01:27:01 AM (6 years ago)
Author:
boonebgorges
Message:

Introduces template hierarchy for top-level theme compat templates

The "top-level" template is the outermost template included by theme
compatibility. As of BuddyPress 1.7, a stack of template names is checked when
BP decides which top-level template to use: plugin-buddypres.php,
buddypress.php, community.php, etc. (See bp_get_theme_compat_templates().)

This changeset introduces an additional level of template hierarchy, so that
themes may provide top-level templates that are specific to the current
component, such as blogs/index-directory.php, or specific to the current item,
action, or status, such as groups/single/index-id-{$group_id}.php. In this way,
BP's top-level template hierarchy becomes more flexible for theme devs, and
more closely parallels the template hierarchy used by WordPress.

Note that this changeset only implements hierarchy for the top-level templates.
Inner template parts may receive a parallel hierarchy in a future version of
BuddyPress.

Fixes #4639

Props r-a-y

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-screens.php

    r7193 r7212  
    319319 *
    320320 * This class sets up the necessary theme compatability actions to safely output
    321  * group template parts to the_title and the_content areas of a theme.
     321 * activity template parts to the_title and the_content areas of a theme.
    322322 *
    323323 * @since BuddyPress (1.7)
     
    351351            do_action( 'bp_activity_screen_index' );
    352352
     353            add_filter( 'bp_get_buddypress_template',                array( $this, 'directory_template_hierarchy' ) );
    353354            add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) );
    354355            add_filter( 'bp_replace_the_content',                    array( $this, 'directory_content'    ) );
     
    356357        // Single activity
    357358        } elseif ( bp_is_single_activity() ) {
     359            add_filter( 'bp_get_buddypress_template',                array( $this, 'single_template_hierarchy' ) );
    358360            add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'single_dummy_post' ) );
    359361            add_filter( 'bp_replace_the_content',                    array( $this, 'single_dummy_content'    ) );
     
    362364
    363365    /** Directory *************************************************************/
     366
     367    /**
     368     * Add template hierarchy to theme compat for the activity directory page.
     369     *
     370     * This is to mirror how WordPress has {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
     371     *
     372     * @since BuddyPress (1.8)
     373     *
     374     * @param string $templates The templates from bp_get_theme_compat_templates()
     375     * @return array $templates Array of custom templates to look for.
     376     */
     377    public function directory_template_hierarchy( $templates ) {
     378        // Setup our templates based on priority
     379        $new_templates = apply_filters( 'bp_template_hierarchy_activity_directory', array(
     380            'activity/index-directory.php'
     381        ) );
     382
     383        // Merge new templates with existing stack
     384        // @see bp_get_theme_compat_templates()
     385        $templates = array_merge( (array) $new_templates, $templates );
     386
     387        return $templates;
     388    }
    364389
    365390    /**
     
    394419
    395420    /**
     421     * Add custom template hierarchy to theme compat for activity permalink pages.
     422     *
     423     * This is to mirror how WordPress has {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
     424     *
     425     * @since BuddyPress (1.8)
     426     *
     427     * @param string $templates The templates from bp_get_theme_compat_templates()
     428     * @return array $templates Array of custom templates to look for.
     429     */
     430    public function single_template_hierarchy( $templates ) {
     431        // Setup our templates based on priority
     432        $new_templates = apply_filters( 'bp_template_hierarchy_activity_single_item', array(
     433            'activity/single/index.php'
     434        ) );
     435
     436        // Merge new templates with existing stack
     437        // @see bp_get_theme_compat_templates()
     438        $templates = array_merge( (array) $new_templates, $templates );
     439
     440        return $templates;
     441    }
     442
     443    /**
    396444     * Update the global $post with the displayed user's data
    397445     *
Note: See TracChangeset for help on using the changeset viewer.