将以下函数放入函数中。php。它将(子)类别及其父类别的ID添加到数组中,删除重复项并返回数组:
function wpse80138_get_cat_ids( $post_id )
{
$array = array();
$cats = get_the_category( $post_id );
foreach( $cats as $cat ) {
$array[] = $cat->term_id;
// parents
if( $cat->category_parent )
$array[] = $cat->category_parent;
// children
$subs = get_categories( \'child_of=\' . $cat->term_id );
foreach( $subs as $sub )
$array[] = $sub->term_id;
}
return implode( \',\', array_unique( $array ) );
}
将该功能用于安布罗斯石:
$cats = wpse80138_get_cat_ids( get_the_ID() );
next_post_link_plus( array( \'in_cats\' => $cats ) );