starting to implement alphabetical filter in category page

This commit is contained in:
Jonas Heinrich 2020-06-12 15:09:54 +02:00
parent 0a6ae01982
commit 77306b737b
3 changed files with 64 additions and 3 deletions

View file

@ -4,6 +4,30 @@ Template Name: Bestand
*/
get_header();
$numberofusers = $wpdb->get_results( "
SELECT post_title
FROM {$wpdb->posts}
WHERE post_type = 'post' and post_status = 'publish'
ORDER BY post_title ASC" );
//echo '<pre>'; print_r($numberofusers); echo '</pre>';
$args = array(
'cat' => $categories[0]->cat_ID,
'orderby' => 'title',
'order' => 'ASC',
);
$query = new WP_Query( $args );
$available_chars = [];
if ( $query->have_posts() ) {
while ( $query->have_posts() ) :
$query->the_post();
array_push($available_chars, substr(get_the_title(),0,1));
endwhile;
wp_reset_postdata();
};
?>
<main>
@ -47,9 +71,18 @@ get_header();
<div class="tx-indexedsearch-form">
<label for="tx-indexedsearch-searchbox-sword"><?php _e('Ergebnisse filtern', 'kit'); ?>:</label>
<div>
<ul>
<li>Alle</li>
<li>A</li>
<ul class="catFilter">
<li class='available active'><a href=#>Alle</a></li>
<?php
$chars = array("0-9", "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>