web-wordpress-kit/kit/category-bestand.php

122 lines
3.2 KiB
PHP

<?php
/*
Template Name: Bestand
*/
get_header();
$category_id = get_cat_ID('Bestand');
$args = array(
'cat' => $category_id,
'orderby' => 'title',
'order' => 'ASC',
'nopaging' => true,
);
$query = new WP_Query( $args );
$available_chars = [];
if ( $query->have_posts() ) {
while ( $query->have_posts() ) :
$query->the_post();
array_push($available_chars, mb_substr(get_the_title(),0,1,"utf-8"));
endwhile;
wp_reset_postdata();
};
?>
<main>
<?php
the_post();
get_template_part( 'template-parts/content', 'category' );
?>
<section class="background-color-white category" style="margin-top: -7rem;">
<div class="content-wrap">
<div class="tx-indexedsearch">
<div id="c139" class="frame frame-default frame-type-list frame-layout-0">
<div class="tx-indexedsearch">
<div class="tx-indexedsearch-searchbox">
<fieldset>
<div class="tx-indexedsearch-form">
<label for="tx-indexedsearch-searchbox-sword">
<?php _e('Ergebnisse filtern', 'kit'); ?>:
</label>
<div>
<ul class="catFilter">
<li class='available active'><a href=#>Alle</a></li>
<?php
$chars = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "Ä", "Ü", "Ö");
foreach($chars as $item) {
if (in_array($item, $available_chars)) {
echo "<li class='available'><a href=#>".$item."</a></li>";
} else {
echo "<li>".$item."</li>";
};
};
?>
</ul>
</div>
</div>
</fieldset>
</div>
</div>
</div>
</div>
<ul class="bestandliste">
<?php
$args = array(
'cat' => $category_id,
'orderby' => 'title',
'order' => 'ASC',
'nopaging' => true,
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
while ( $query->have_posts() ) :
$query->the_post();
$first_char = mb_substr( esc_html( get_the_title() ) ,0,1,"utf-8" );
if ($last_first_char === $first_char) {
echo '<li>
<a href="' . esc_url( get_permalink() ) . '">
' . esc_html( get_the_title() ) . '
</a>
</li>';
} else {
echo '</ul>
<ul class="bestandliste" id="' . $first_char . '">
<li>
<a href="' . esc_url( get_permalink() ) . '">
' . esc_html( get_the_title() ) . '
</a>
</li>';
$last_first_char = $first_char;
};
endwhile;
wp_reset_postdata();
endif;
?>
</ul>
</div>
</section>
</main>
<?php
get_template_part('template-parts/sidebar');
get_footer();