Ich würde gerne einen ganz simplen Filter in meine Seite einbauen, mit dem ich die Kategorien z.B. eines Portfolios filtern kann. Diesen Filter möchte ich gerne auf verschiedene CPTs anwenden, sodass ich keine Taxonomie fest hineinschreiben kann.
- Custom Post-Type-Archive: http://www.domain.de/portfolio - geht nicht
- Custom Post-Type-Page (page-portfolio): - geht nicht
- Blog Custom-Formats: http://www.domain.de/taxonomy/term/ - geht nicht
- Custom Post-Type-Term-Page: http://www.domain.de/taxonomy/term- GEHT!!!
PHP
<?php
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$incname = $term->taxonomy;
$args = array( 'hide_empty=0' );
$terms = get_terms( $incname, $args );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$count = count( $terms );
$i = 0;
$term_list = '
<div class="btn-group" role="group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
Kategorie filtern
<span class="caret"></span>
</button><ul class="dropdown-menu" role="menu">
';
foreach ( $terms as $term ) {
$i++;
$term_list .= '<li><a href="' . get_term_link( $term ) . '" title="' . sprintf( __( 'View all post filed under %s', 'my_localization_domain' ), $term->name ) . '">' . $term->name . '</a></li>';
if ( $count != $i ) {
}
else {
$term_list .= '<li class="divider"></li><li><a href="' . get_post_type_archive_link( get_post_type( $post ) ) . '" title="' . sprintf( __( 'View all posts', 'my_localization_domain' ), $term->name ) . '"> Alle </a></li> </ul></div>';
}
}
echo $term_list;
} ?>
Alles anzeigen