Created
August 23, 2018 18:04
-
-
Save amielucha/a9f4b33ced188a5e7923613a097cb143 to your computer and use it in GitHub Desktop.
WordPress Category Dropdown Nav
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
<?php | |
/** | |
* Category Dropdown. Can be used for listing categories on WP archive pages. | |
*/ | |
?> | |
<select onchange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);"> | |
<option value="<?php echo get_permalink( get_option( 'page_for_posts' ) ) ?>">All</option> | |
<?php | |
$cats = get_categories(); | |
$current_category = get_category( get_query_var( 'cat' ) ); | |
foreach ($cats as $key => $cat) | |
echo '<option '. ( $cat->cat_ID === $current_category->cat_ID ? 'selected' : '' ) .' value="' . get_category_link( $cat->cat_ID ) . '">' . $cat->name . '</option>'; | |
?> | |
</select> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment