php - Wordpress Dropdown Categories All Links to Single -
i'm having issue where, though page renders "all" selected in dropdown, if go category (renders fine) , "all" in dropdown, see single post. instead of displayed page of categories. need page render same page "all" regardless. thoughts?
wp_dropdown_categories('show_option_all=all&hide_empty=0&show_count=0&orderby=name&echo=0');
i did similar post on wpse lastly week , seems 2 might related. convenience, here post
here variation of code use. i'm using get_categories()
here accomplish same goal. had adjust code create acceptable need.
there other modifications have create work. when select all categories
option, taken page display ever need display. page have manually create
there no index archive pages in wordpress might know. (check out this post have done on same subject). means is, domain.com/category/
returns 404.
so, create work, you'll have create re-create of page.php, rename page-category.php (see codex on how create custom page templates), open up, create custom query display display when page visited
you need create page in end. suggest utilize slug category
when visit domain.com/category/
, page displayed. (just remember, cannot create kid pages page, break hierarchy). have made code go domain.com/category/
when all categories
selected
apart that, code should work fine. need check url structures maybe, , set parameters in get_categories()
suite needs. here drop downwards code.
<select name="event-dropdown" onchange='document.location.href=this.options[this.selectedindex].value;'> <option value=""><?php echo esc_attr(__('select category')); ?></option> <?php $option = '<option value="' . get_option('home') . '/category/">all categories</option>'; // alter category custom page slug $categories = get_categories(); foreach ($categories $category) { $option .= '<option value="'.get_option('home').'/category/'.$category->slug.'">'; $option .= $category->cat_name; $option .= ' ('.$category->category_count.')'; $option .= '</option>'; } echo $option; ?> </select>
edit
i had thought here come in handy. i've done reply on displaying categories in list post titles under specific category. same thought can used in page-category.php template.
when user selects all categories
option, taken page list categories , post title.
here finish code: (for explanation of code, see post here)
in functions.php
add_action( 'transition_post_status', 'publish_new_post', 10, 3 ); function publish_new_post() { delete_transient( 'category_list' ); }
in template need display list
<?php if ( false === ( $q = get_transient( 'category_list' ) ) ) { $args = array( 'posts_per_page' => -1 ); $query = new wp_query($args); $q = array(); while ( $query->have_posts() ) { $query->the_post(); $a = '<a href="'. get_permalink() .'">' . get_the_title() .'</a>'; $categories = get_the_category(); foreach ( $categories $key=>$category ) { $b = '<a href="' . get_category_link( $category->cat_id ) . '">' . $category->name . '</a>'; } $q[$b][] = $a; // create array category names , post titles } /* restore original post info */ wp_reset_postdata(); set_transient( 'category_list', $q, 12 * hour_in_seconds ); } foreach ($q $key=>$values) { echo $key; echo '<ul>'; foreach ($values $value){ echo '<li>' . $value . '</li>'; } echo '</ul>'; } ?>
php wordpress drop-down-menu categories
No comments:
Post a Comment