我已经成功地设置了一个页面模板来显示我的自定义帖子类型"books",并按自定义字段(作者的第二个名字)进行排序:
<?php
// Define custom query parameters
$custom_query_args = array(
'post_type' => 'books',
'showposts' => 10,
'meta_key' => 'author_second_name',
'orderby' => 'meta_value date',
'order' => 'ASC'
);
// Get current page and append to custom query parameters array
$custom_query_args['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
// Instantiate custom query
$custom_query = new WP_Query( $custom_query_args );
// Pagination fix
$temp_query = $wp_query;
$wp_query = NULL;
$wp_query = $custom_query;
// Output custom query loop
if ( $custom_query->have_posts() ) : ?>
在我的档案页面上,我已经成功地实现了A-Z分页,并尝试对其进行调整。在我的作者页面上使用以下方法:
<?php echo "<a href=http://mywebsite.com/authors/?$query_string&number=true' ># </a> - ";
foreach (range('A', 'Z') as $i)
{
$letter = strtolower($i);
echo "<a href='mywebsite.com/authors/?$query_string&letter=$letter' >$i </a> - ";
}
echo "<a href=http://mywebsite.com/authors/?$query_string' >All </a>"; ?>
不出所料,这似乎并不奏效。为了走到这一步,我已经编写了各种各样的代码,并且原则上理解了其中的大部分,但在尝试实现这一点时有点困难。
有人能帮忙吗?
我后来发现了一种更好的方法来查询这里的所有内容:
http://wordpress.mcdspot.com/2012/04/12/select-posts-on-the-first-letter-of-a-custom-field/