WordPress:按照帖子计数顺序显示分类法的作者

时间:2014-08-06 08:37:23

标签: wordpress taxonomy author

我想显示分类法的作者列表,并按帖子计数排序列表。 最后,我想根据他们的帖子数量显示不同大小的作者的图像。

这是我所拥有的(来源:http://blog.brianjohnsondesign.com/dropdown-list-of-authors-with-posts-in-category/):

<ul>
              <?php //Code to get a list of all authors with posts in this category, and then create a dropdown list of their names with links to their page

                    $category = get_queried_object();
                    $taxonomy_name = 'themen'; //Change to reflect the name of your custom taxonomy
                    $current_category = $category->slug;
                    $author_array = array();
                    $args = array(
                    'posts_per_page' => -1,
                    'post_type' => 'post', //Change to your custom post type
                    'tax_query' => array(
                            array(
                                'taxonomy' => 'themen', //Change to reflect the name of your custom taxonomy
                                'field' => 'slug',
                                'terms' => $current_category
                                ),
                                ),
                    'orderby' => 'author',
                    'order' => 'ASC'
                    );
                    $cat_posts = get_posts($args);
                    foreach ($cat_posts as $cat_post) :
                    if (!in_array($cat_post->post_author,$author_array)) {
                    $author_array[] = $cat_post->post_author;
                    }
                    endforeach;
                    foreach ($author_array as $author) :
                    $auth = get_userdata($author)->display_name;
                    $nicename = get_userdata($author)->user_nicename;
                    //echo '<li><a href="' . get_term_link( $category->slug, $taxonomy_name ) . '/' . $nicename . '">' . $auth . '</a></li>';
                    echo '<li><a href="/author/' . $nicename . '/">' . $auth . '</a></li>';
                    endforeach;
                    ?>
                </ul>

这是正确的方向吗? 我不知道如何命令作者。 :(

1 个答案:

答案 0 :(得分:1)

你绝对可以使用WP查询。如果你正确使用它,WordPress查询是一个非常强大的工具。或者您可以使用名为list_authors

的WP函数列出作者
<?php wp_list_authors( $args ); ?> 



<?php $args = array(
'orderby'       => 'post_count', 
'order'         => 'DESC', 
'number'        => null,
'optioncount'   => false, 
'exclude_admin' => true, 
'show_fullname' => false,
'hide_empty'    => true,
'echo'          => true,
'feed'          => [empty string], 
'feed_image'    => [empty string],
'feed_type'     => [empty string],
'style'         => 'list',
'html'          => true,
'exclude'       => [empty string],
'include'       => [empty string] ); ?>