Tag Info

Hot answers tagged

2

Just use the break statement to abort after the first cat that is found and that is a child category. foreach ( get_the_category() as $cat ) { if ( cat_is_ancestor_of( 10, $cat ) ) { printf( '<a href="%s">%s</a>', get_category_link( $cat->cat_ID), echo $cat->cat_name ); ...


2

get_query_var will get the category from the main query, and it is only going to be set for some pages, such as category archives. It is not set for "single" pages or tag archives or a many other kids of "pages". The value that get_query_var returns is something like a 'search' variable. It will be set when the query is instructed to look for posts in a ...


1

You can use get_query_var( ) to fetch the current category: $cat = get_query_var( 'cat' ); You can use this $cat in the exclude parameter of wp_dropdown_categories( ) to hide the current category: $args = array( 'show_option_none' => __( 'Select A Category' ), 'show_count' => 1, 'exclude' => $cat ); wp_dropdown_categories( $args );



Only top voted, non community-wiki answers of a minimum length are eligible