Last active
June 14, 2016 09:06
-
-
Save eri-trabiccolo/8d57c81198fc0e1030a8 to your computer and use it in GitHub Desktop.
different featured pages in different 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
$page_fpc = array( | |
'2' => array( | |
'per_row' => 3, | |
'fp' => array( | |
'one' => '8', | |
'two' => '9', | |
'three' => '10', | |
'4' => '12', | |
'5' => '7' | |
), | |
'location' => '__before_footer', | |
), | |
'8' => array( | |
'fp' => array( 'one' => '2', 'two' => '4', 'three' => '1', '4' => '12'), | |
), | |
); | |
function is_eligible_page(){ | |
global $page_fpc; | |
return is_page(array_keys($page_fpc)); | |
} | |
add_action('template_redirect', 'tc_fpc_on_another_page'); | |
function tc_fpc_on_another_page() { | |
if ( ! is_eligible_page() ) | |
return; | |
global $page_fpc; | |
// show featured pages in our pages | |
add_filter( 'tc_show_fp' , '__return_true'); | |
// number of featured pages | |
add_filter( 'fpc_featured_pages_ids', 'my_featured_page_ids', 20); | |
function my_featured_page_ids($fpc_ids){ | |
global $page_fpc; | |
return array_keys($page_fpc[ get_the_ID()]['fp']); | |
} | |
// number of fp per line | |
add_filter('fpc_per_line', 'my_fpc_per_line'); | |
function my_fpc_per_line( $fpl ){ | |
global $page_fpc; | |
return isset($page_fpc[ get_the_ID() ]['per_row']) ? $page_fpc[ get_the_ID() ]['per_row'] : $fpl; | |
} | |
// return our per page featured pages and an empty text so the excerpt will be taken | |
foreach ( $page_fpc[get_the_ID()]['fp'] as $key => $value){ | |
add_filter("tc_fpc_get_opt_tc_featured_page_{$key}", 'my_fp', 20, 2); | |
add_filter("tc_fpc_get_opt_tc_featured_text_{$key}", '__return_empty_string', 20); | |
} | |
function my_fp( $value, $option_name){ | |
global $page_fpc; | |
return $page_fpc[ get_the_ID() ]['fp'][substr($option_name, strlen('tc_featured_page_') ) ]; | |
} | |
// change location | |
add_filter('tc_fp_location', 'my_fp_location', 20); | |
function my_fp_location( $loc ){ | |
global $page_fpc; | |
return isset($page_fpc[ get_the_ID() ]['location']) ? $page_fpc[ get_the_ID() ]['location'] : $loc; | |
} | |
}//end fpc on another page |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment