Skip to content

Changing Narrow Templates

Jim Reevior edited this page Aug 14, 2018 · 1 revision

Changing Narrow Content

When a theme meets the following requirements, it will activate "narrow" content.

BU_RESPONSIVE_POSTS_SIDEBAR_SHOW_BOTTOM constant is defined and not set to false.

OR

BU_RESPONSIVE_POSTS_SIDEBAR_SHOW_BOTTOM is not defined but "Keep the posts sidebar on bottom" is checked in the Customizer.

AND

The sidebar location is set to bottom.

OR

Viewing a single BU Calendar event.

When these conditions are met, the following will be considered "narrow":

  • Single profiles.
  • Single posts.
  • Single calendar events.
  • Profile archives.
  • Post archives.

There are several filters that can be used to adjust what should be considered narrow.

Blog Page

By default, the blog page is considered narrow. This can be changed with the r_narrow_blog_page filter.

<?php
/**
 * The blog page should not be narrow.
 */
add_filter( 'r_narrow_blog_page', '__return_false' );

Single Post Types

By default, there are two post types considered narrow when is_singular() is true: posts, and profiles.

<?php
/**
 * Add degree programs and remove posts from narrow post types.
 *
 * @param array $post_types Post types to consider narrow when is_singular().
 *
 * @return array Narrow post types.
 */
function mytheme_r_narrow_single_templates( $post_types ) {
	$post_key = array_search( 'post', $post_types, true );

	if ( false !== $post_key ) {
		unset( $post_types[ $post_key ] );
	}

	$post_types[] = 'degree_program';

	return $post_types;
}
add_filter( 'r_narrow_single_templates', 'mytheme_r_narrow_single_templates' );

Archives

By default, there are two post type archives considered narrow: posts, and profiles. These can be removed, and more can be added.

<?php
/**
 * Define the degree program archive as narrow.
 *
 * @param array $post_types Post type archives to consider narrow.
 *
 * @return array Narrow post type archives.
 */
function mytheme_r_narrow_archive_templates( $post_types ) {
	$post_types[] = 'degree_program';

	return $post_types;
}
add_filter( 'r_narrow_archive_templates', 'mytheme_r_narrow_archive_templates' );

Page Templates

By default, there are two page templates that are considered narrow: page-templates/news.php and profiles.php. More can be added using the r_narrow_page_templates filter.

<?php
/**
 * Add narrow page templates.
 *
 * @param array $page_templates Page templates to consider narrow.
 *
 * @return array Narrow page templates.
 */
function mytheme_r_narrow_page_templates( $page_templates ) {
	$page_templates[] = 'page-templates/custom-template.php';
	$page_templates[] = 'page-templates/calendar.php';

	return $page_templates;
}
add_filter( 'r_narrow_page_templates', 'mytheme_r_narrow_page_templates' );

Other Scenarios

If none of the above scenarios fits the content you are trying to define as narrow, there is a final filter, r_is_narrow_template, that you can use. The final result of the r_is_narrow_template() function is passed through this filter.

<?php
/**
 * Don't consider the Dean's profile to be narrow.
 *
 * @param bool $is_narrow Whether the current page is narrow.
 *
 * @return bool Whether the current page is narrow.
 */
function mytheme_r_narrow_page_templates( $is_narrow ) {
	if ( ! is_singular( 'profile' ) ) {
		return $is_narrow;
	}

	$dean_profile_id = (int) get_option( 'mytheme_dean_profile_id' );

	if ( empty( $dean_profile_id ) ) {
		return $is_narrow;
	}

	if ( get_queried_object_id() === $dean_profile_id ) {
		return false;
	}

	return $is_narrow;
}
add_filter( 'r_narrow_page_templates', 'mytheme_r_narrow_page_templates' );

Welcome to Responsive!

Get started

Configuration

Build child themes

Sass

Javascript

PHP

Shortcodes

Templates

GitHub

Tasks

Contribute to the framework

Code Examples

BU Developer Resources

Clone this wiki locally