我正在处理自定义帖子类型存档,我想添加 A-Z 过滤菜单。 我设法按照这个线程(Create letterical Pagination in wordpress)让它正常工作,但我不明白我的初始页面(/exposants)如何显示所有结果。
<div class="exposant__filter" id="exposants">
<a href="/exposants/#exposants"><?php _e('Tout', 'festival'); ?></a>
<?php
$posts = get_posts(array(
'numberposts' => -1,
'post_type' => 'exposant',
'orderby' => 'title',
'order' => 'ASC',
));
$firstLetters = array();
foreach($posts as $post) {
$title = $post->post_title;
$startingLetter = substr($title, 0, 1);
$dupeFirstLetters[] = $startingLetter;
$firstLetters = array_unique($dupeFirstLetters);
sort($firstLetters);
}
foreach($firstLetters as $letter) {
echo "<a href=\"?lettre=$letter\">$letter</a>";
}
if(!empty($_GET['lettre'])) {
$letter = $_GET['lettre'];
}
else {
$letter = $firstLetters[0];
} ?>
</div>
<?php
$exposantsArchive = new WP_Query(array(
'posts_per_page' => -1,
'post_type' => 'exposant',
'orderby' => 'title',
'order' => 'ASC',
)); ?>
<div class="row row--2col u-m-top--8">
<?php
while($exposantsArchive->have_posts()) {
$exposantsArchive->the_post();
$first_letter = strtoupper(substr(apply_filters('the_title',$post->post_title),0,1));
$logo = get_field('logo');
if($first_letter == strtoupper($letter)) { ?>
<div class="exposant__thumb col--padding-right">
<div class="exposant__logo">
<img src="<?php echo $logo['url'] ?>" alt="<?php echo $logo['alt'] ?>">
</div>
我想我必须替换 else {$letter = $firstLetters[0];} 但我不知道用什么替换。
预先感谢您的宝贵支持。
慕少森