Thetwentyfourteen_get_featured_posts
过滤器:
需要一些挖掘,才能弄清楚
twentyfourteen_get_featured_posts
过滤器用于第214主题;-)
特色内容是fetched 使用:
$featured_posts = twentyfourteen_get_featured_posts();
但该函数仅为一行:
return apply_filters( \'twentyfourteen_get_featured_posts\', array() );
那么肉在哪里?
我们在Featured_Content
类,从这个开始line:
add_filter( $filter, array( __CLASS__, \'get_featured_posts\' ) );
在哪里
$filter
来自:
$filter = $theme_support[0][\'featured_content_filter\'];
其中:
$theme_support = get_theme_support( \'featured-content\' );
<小时>英寸
functions.php
我们发现:
// Add support for featured content.
add_theme_support( \'featured-content\', array(
\'featured_content_filter\' => \'twentyfourteen_get_featured_posts\',
\'max_posts\' => 6,
) );
因此,我们最终看到:
$filter === \'twentyfourteen_get_featured_posts\';
示例:要覆盖默认的特色内容帖子,您可以尝试以下操作:
add_filter( \'twentyfourteen_get_featured_posts\', function( $posts ){
// Modify this to your needs:
$posts = get_posts( array(
\'post_type\' => array( \'cpt1\', \'cpt2\' ),
\'posts_per_page\' => 6,
\'featured_tax\' => \'featured_term\'
) );
return $posts;
}, PHP_INT_MAX );
下一步是将其连接到主题定制器,并可能缓存它。
希望您可以从这里继续旅程;-)