我正在处理目录员工列表。我去了一个自定义的解决方案,因为这个目的插件太复杂或太简单,我所寻找的。 所以我创建了这个自定义职位类型“职员”附加了自定义分类法以及它(科学,数学,管理等),所以我有一个查询,我得到了所有列在表中的职位,我的代码如下所示。通过自定义字段第一个字母过滤查询 - Wordpress
<table class="directorytable">
<thead>
<th class="first-th">Portrait</th>
<th>Name</th>
<th>Position</th>
<th>Phone</th>
<th style="width:60px !important;text-align:center;">Email </th>
<th style="width:60px !important;text-align:center;">Website </th>
<th style="width:60px !important;text-align:center;">Details </th>
</thead>
<?php query_posts(array('post_type'=>'staff','orderby'=>'meta_value','meta_key'=>'staff_last_name','order'=>'asc'))?>
<?php while(have_posts()): the_post();?>
<tr>
<td class="first-td"><a rel="lightbox" href="<?php the_permalink(); ?>"/><img src="<?php the_field('staff_portrait');?>" style="border-radius:2px; width:35px;"/></a></td>
<td><a rel="lightbox[1]" href="<?php the_permalink();?>"><?php the_field('staff_name');?> <?php the_field('staff_last_name');?></a> </td>
<td><?php the_field('staff_position'); ?></td>
<td><?php the_field('staff_phone');?> | <strong>Ext: </strong><?php the_field('staff_extension')?></td>
<td style="width:60px; text-align:center;"><a href="mailto:<?php the_field('staff_email');?>"><img src="/images/directory/mail.png"/></a></td>
<td style="width:60px; text-align:center;"><?php if(get_post_meta($post->ID,'staff_website', true)){?><a target="_blank" href="<?php the_field('staff_website');?>"><img src="/images/directory/document-globe.png"/></a><?php } else {?><?php echo '';?><?php } ?></td>
<td style="width:60px; text-align:center;"><a rel="lightbox[2]" href="<?php the_permalink();?>"><img src="/images/directory/magnifier-zoom.png"/></a></td>
</tr>
<?php endwhile; ?>
</table>
所以这个清单工作得很好,但我的客户要求我添加一个字母索引。因此,我需要在结果前列出范围a-z,然后单击,只显示他们的“staff_last_name”自定义字段(我正在使用ACF)的帖子以选定的字母开头。
我尝试过一些像AZIndex,WP-Snap等插件,但没有一个为我工作。
我很感激任何关于此事的建议/解决方案。
嗨Hobo,很好的回答,非常感谢你花时间解释我所有的......可悲的是我必须说我不明白它100%。我不想生成我想在表格上方显示的索引A-Z。你的解释背后的想法是当我按下字母时产生一个新的查询。我没有定义任何东西,因为我诚实地不知道如何处理这个问题。对不起,再次感谢。 – Jaypee 2012-04-11 20:52:15
使用BETWEEN并创建了一个数组,该数组拉动搜索到的字母,然后递增它为下一个值完美工作,以元字段的第一个字母搜索“帖子”。谢谢 – philhoyt 2015-07-02 20:44:14