Description
This filter is used to change the current Conductor content layout properties.
This filter is executed when the Conductor::get_conductor_content_layout()
function is called.
Technical Details
Type: Filter
Parameters:
$conductor_content_layout (array): Current content layout properties
Return Value: array, The Conductor content layout data structure if Conductor::is_conductor()
Resources
- View on GitHub
Conductor::get_conductor_content_layout()
Conductor_Template_Loader::template_include()
Conductor::get_conductor_content_layout()
- Guide: Conductor Content Layouts
Examples
The following example sets the correct Conductor content layout properties for a custom post type named “test”. It can be used in conjunction with the examples on the conductor_is_conductor
and conductor_content_layout_data
documentation pages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This function sets the correct Conductor content layout properties for a post within a custom post type. | |
*/ | |
add_filter( 'conductor_content_layout', 'my_conductor_content_layout' ); | |
function my_conductor_content_layout( $conductor_content_layout ) { | |
global $post; | |
// is Conductor | |
$is_conductor = Conductor::is_conductor(); | |
// Grab Conductor options | |
$conductor_options = Conductor_Options::get_options(); | |
// Bail if we aren't "Conductor", there aren't any Conductor content layouts, or we already have Conductor content layout data | |
if ( ! $is_conductor || empty( $conductor_options['content_layouts'] ) || ! empty( $conductor_content_layout ) ) | |
return $conductor_content_layout; | |
// Singular "test" posts | |
if ( is_singular( 'test' ) ) | |
// Loop through content layouts | |
foreach ( $conductor_options['content_layouts'] as $content_layout ) | |
// Found a match (validating contetnt type, ID, and whether or not a content layout value is set) | |
if ( $content_layout['field_type'] === $post->post_type && $content_layout['field_id'] === $post->ID && ! empty( $content_layout['value'] ) ) { | |
// A Conductor content layout exists for this piece of content, set the reference | |
$conductor_content_layout = $content_layout; | |
// Break out of the loop | |
break; | |
} | |
return $conductor_content_layout; | |
} |