作者档案和作者类别

时间:2013-07-10 作者:Marin Bînzari

问题描述:

我应该写一个博客,比如说4位作者(可能更多)
博客应该有一个页面“blog-page-1”(无侧边栏),上面是每个作者的最后一篇文章,还有一个页面“blog-page-2”(带侧边栏),上面只显示特定作者的文章,这取决于用户点击的是哪篇文章“blog-page-1”
此外,博客侧边栏应包含该作者最近发表的文章、存档和类别,单击这些内容将显示“blog-page-2”,其中包含特定内容。

如何制作档案和特定作者的类别?

第“blog-Page-1”页我会照写的做here (http://wordpress.org/support/topic/query-post-to-show-one-post-per-author).

我还发现了作者帖子的显示this (https://wordpress.stackexchange.com/questions/71127/list-authors-posts-in-author-php)

2 个回复
最合适的回答,由SO网友:Marin Bînzari 整理而成

所以我做了一部分,我想我应该把它贴在这里:)这是索引的一部分。php。默认情况下,它会按每个作者显示一篇文章,或者如果选择了一篇文章,则会显示文章的百分位和前面的两篇文章。

        if(!is_single()) {
            //get all users, iterate through users, query for one post for the user,
            //if there is a post then display the post title, author, content info
            $blogusers = get_users(\'blog_id=1&orderby=nicename&role=author\');
            //print_r($blogusers);
            //die();
            if ($blogusers) {
                foreach ($blogusers as $bloguser) {
                    $args = array(
                        \'author\' => $bloguser->ID,
                        \'showposts\' => 1
                    );
                    $my_query = new WP_Query($args);
                    //print_r($my_query);
                    //die();
                    if( $my_query->have_posts() ) {
                        // $user = get_userdata($bloguser->ID);
                        // echo \'This is one post for author with User ID: \' . $user->ID . \' \' . $user->user_firstname . \' \' . $user->user_lastname;
                        while ($my_query->have_posts()) : $my_query->the_post();
                            get_template_part(\'content\');
                        endwhile;
                    }
                }
            }
        } else {
            if(have_posts()) {
                while ( have_posts() ) : the_post();
                    get_template_part(\'content\');
                    $author_ID = get_the_author_meta(\'ID\');
                    $datetime = get_the_date(\'Y-m-d H:i:s\');
                endwhile;

                wp_reset_postdata();

                //echo $datetime;

                $args = array(
                    \'author\' => $author_ID,
                    \'showposts\' => 2
                );

                function filter_where( $where = \'\' ) {
                    global $datetime;
                    // posts for March 1 to March 15, 2010
                    $where .= " AND post_date < \'" . $datetime . "\'";
                    return $where;
                }

                add_filter( \'posts_where\', \'filter_where\' );
                $my_query = new WP_Query($args);
                remove_filter( \'posts_where\', \'filter_where\' );

                if( $my_query->have_posts() ) {
                    // $user = get_userdata($bloguser->ID);
                    // echo \'This is one post for author with User ID: \' . $user->ID . \' \' . $user->user_firstname . \' \' . $user->user_lastname;
                    while ($my_query->have_posts()) : $my_query->the_post();
                        $more = 0;
                        get_template_part(\'content\', \'special\');
                    endwhile;
                }
            }
        }
关于类别,我为每个作者创建了一个父类别,并显示其子类别。

    global $wp_query;
    $post = $wp_query->post;
    //print_r($wp_query->post);

    $categories = get_the_category($post->ID);
    $category = isset($categories[0]) ? $categories[0] : 0;
    foreach($categories as $c) {
        if($c->parent == 0) $category = $c;
    }

    //print_r($category);

    $args = array(
        \'child_of\' => $category->cat_ID,
        \'hide_empty\' => 0,
        \'pad_counts\' => true
    );

    $categories = get_categories( $args );
    print_r($categories);
对于作者档案,我定制了wordpress函数wp_get_archives() 像这样:

    /* Replace old $defaults */
    $defaults = array(
        \'type\' => \'monthly\', \'limit\' => \'\',
        \'format\' => \'html\', \'before\' => \'\',
        \'after\' => \'\', \'show_post_count\' => false,
        \'echo\' => 1, \'order\' => \'DESC\',
        \'post_author\' => \'\',
    );

    /* ... */

    /* And the $where filter */
    $where = apply_filters( \'getarchives_where\', "WHERE post_type = \'post\' AND post_status = \'publish\'" . ($post_author != \'\' ? \' AND post_author = \' . $post_author : \'\'), $r );
也许有更好的解决方案,但我用这个。

最后,当前作者的最新帖子

    /* Get posts related to curent post author */
    function get_related_author_posts($number = 5) {
        global $authordata, $post;

        $authors_posts = get_posts( array( \'author\' => $authordata->ID, \'post__not_in\' => array( $post->ID ), \'posts_per_page\' => $number ) );
        $output = \'<ul>\';

        foreach ( $authors_posts as $authors_post ) {
            $output .= \'<li><a href="\' . get_permalink( $authors_post->ID ) . \'">\' . apply_filters( \'the_title\', $authors_post->post_title, $authors_post->ID ) . \'</a></li>\';
        }

        $output .= \'</ul>\';

        return $output;
    }

SO网友:calvares

您可以通过调用get_header ( "authorPaul" );然后验证作者是否有帖子
如果有,显示最后一个
存档也是如此。

结束

相关推荐

Author Profile URL

我有2个用户角色。“摄影师”和“订阅者”我已经确定了我的作者。像这样的php<?php get_header(); $thisauthor = get_userdata(intval($author)); $author_user = $wp_query->get_queried_object(); ?> <div id=\"main\"> <?php if (u