0

Description of the problem:

I should make a blog with, let's say 4 authors (may be more).
The blog shoud have a page 'blog-page-1' (without sidebar) on which will be the last post of each author and a page 'blog-page-2' (with sidebar) on which will be diplayed only posts of a specific author, depends on which post user clicked on 'blog-page-1'.
Also blog sidebar should have recent-posts, archives and categories of that author, clicking on which will display 'blog-page-2' with the specific content.

Any ideas how to make archives and category of specific author?

Page 'blog-page-1' I will do as is written here (http://wordpress.org/support/topic/query-post-to-show-one-post-per-author).

Also I found for author posts display this (https://wordpress.stackexchange.com/questions/71127/list-authors-posts-in-author-php)

  • Questions are solved here by accepting an answer, not by adding a word to the title. – fuxia Jul 11 '13 at 7:07
0

You can make specific pages (like landing pages) and call a specific header (or footer) template (i.e. header-authorPaul.php) by calling get_header ( "authorPaul" ); and then verifying that the author has post(s).
Show the last one(s) if any.
The same goes for archives.

  • Okay. I will think at it. Now I think to use parent categories for each user. About archives I don't know at moment. – Marin Bînzari Jul 10 '13 at 10:55
  • Question: how do I make url of author archive? – Marin Bînzari Jul 10 '13 at 11:38
0

So. I made a part of it, and I think I should post it here :) This is a part of index.php. It show a post per each author by default, or if a post is selected it shows the post centent and 2 post before it.

        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;
                }
            }
        }

About categories, I made one parent category for each author, and show its subcategories.

    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);

For author archives, I customized the wordpress function wp_get_archives() like so:

    /* 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 );

Maybe there is a better solution, but I use this.

And at the end, recent post of the current author

    /* 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;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.