-
-
Save tenman/6f591b2430c5c739c06a to your computer and use it in GitHub Desktop.
Fixed Raindrops category archives issue
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
// test 1 | |
function raindrops_category_navigation(){ | |
$result = ''; | |
$tmp_id = get_query_var( 'cat'); | |
$tmp_id = absint( $tmp_id ); | |
$sibling = ''; | |
$tmp_parent = get_category_parents( $tmp_id , true, ' » ' ); | |
if( strip_tags( $tmp_parent ) !== get_the_category_by_ID( $tmp_id ). ' » ' ) { | |
$tmp_parent = trim( $tmp_parent ,' » '); | |
$result = str_replace(get_the_category_by_ID( $tmp_id ),'', $tmp_parent ); | |
$result .= sprintf( '<span class="current">%1$s</span> » ', get_the_category_by_ID( $tmp_id ) ); | |
} | |
$tmp_child_ids = get_term_children( $tmp_id, 'category' ); | |
foreach( $tmp_child_ids as $tmp_id ) { | |
$term = get_term_by( 'id', $tmp_id, 'category' ); | |
if( $sibling == $term->parent ) { | |
$category_separator = '|'; | |
$flag = 'sibling'; | |
} else { | |
$category_separator = "»"; | |
$flag = 'parent'; | |
} | |
$category_separator = apply_filters( 'raindrops_category_navigation_separator', $category_separator, $flag ); | |
$result .= " {$category_separator} ". '<a href="' . esc_url( get_term_link( $tmp_id, 'category' ) ) . '">' . esc_html( $term->name ) . "</a>"; | |
$sibling = $term->parent; | |
} | |
return apply_filters( 'raindrops_category_navigation', '<div class="raindrops-category-navigation">'. trim( $result,' » '). '</div>' ); | |
} | |
//test2 | |
function raindrops_post_category_relation() { | |
global $post; | |
$result = array(); | |
$tmp_id = absint( get_query_var( 'cat' ) ); | |
$categories = get_the_category( $post->ID ); | |
foreach ( $categories as $category ) { | |
$category->term_id = absint( $category->term_id ); | |
$parents = get_category_parents( $category->term_id, true, '»' ); | |
$parents_item = str_replace( '<a href="' . get_category_link( $category->term_id ) . '">' . $category->name . "</a>»", '', $parents ); | |
$parents = explode( '»', $parents_item ); | |
if ( ! empty( $parents_item ) ) { | |
$result[] = '<span class="label title parent">'.esc_html__('Parent Category:','Raindrops' ).'</span>'; | |
} | |
foreach ( $parents as $links ) { | |
$result[] = $links; | |
} | |
$replace_check = get_the_category_by_ID( $category->term_id ); | |
$replace_check = get_category_link( $category->term_id ); | |
$tmp_child_ids = get_term_children( $category->term_id, 'category' ); | |
$child_result = ''; | |
$child_ready = array(); | |
if ( ! empty( $tmp_child_ids ) ) { | |
$result[] = '<span class="label title child">'.esc_html__('Child Category:','Raindrops' ).'</span>'; | |
} | |
foreach ( $tmp_child_ids as $tmp_id ) { | |
$tmp_id = absint( $tmp_id ); | |
$term = get_term_by( 'id',$tmp_id , 'category' ); | |
$result[] = '<a href="' . get_term_link( $tmp_id, 'category' ) . '">' . $term->name . "</a>"; | |
} | |
} | |
$result = array_unique( $result ); | |
$result = implode( ' ', $result ); | |
return apply_filters( 'raindrops_post_category_relation', rtrim( $result, ' » ' ) ); | |
} | |
//test3 filterによるセパレータのカスタマイズ | |
add_filter( 'raindrops_category_navigation_separator', 'custom_category_separator', 10, 2 ); | |
function custom_category_separator( $val, $flag ) { | |
if( $flag == 'sibling' ){ | |
return '/'; | |
} | |
return $val; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment