-
Notifications
You must be signed in to change notification settings - Fork 0
Changing Narrow Templates
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.
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' );
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' );
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' );
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' );
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' );
Get started
Configuration
Build child themes
- Customizing CSS in a child theme
- Overriding templates in a child theme
- Code patterns
- Code reviews
- Pulling in Foundation Updates
- Merging and Creating a Pull Request
Sass
Javascript
PHP
- Coding Standards
- PHP Constants
- Temp PHP Code Patterns
- PHP Snippets
- How to Use Hooks
- Action Hooks
- Using Action Hooks To Output Markup
- Filter Hooks
Shortcodes
Templates
GitHub
Tasks
Contribute to the framework
- Framework Development and Release Workflows
- Documentation Template
- Testing your changes
- Creating a new release
- Migration Guide
- Needs Documentation
Code Examples
- Adding Content Container Classes
- Adding News Templates
- Adding Script Dependencies
- Changing Available Layouts and Default Layout
- Displaying a Fancy Gallery
- Loading a Custom Build of Modernizr
- Loading Modernizr in the Footer
- Using Action Hooks To Output Markup
- Understanding get_template_part
BU Developer Resources