• rubhadubh

    (@rubhadubh)


    Hi, I’m new to wordpress but not to php/mysql. I’m creating one blog with multiple users created as Authors.

    I’m missing some piece of understanding and have spent too long searching around…

    I can create a Page for each Author and set that user to be the Page Author. That makes the page show up on my menu properly and with permalinks, the url has /blogs/author_name as intended, but how do I grab the page author info so I can go get all their posts? OR, I can create a list of authors and each link displays the posts of that author, but thee aren’t ‘Pages’ that can be listed in the menu??

    Is there an ‘author’ variable available to me when I create a page template along with other page info? Or am I barking up the wrong tree, and there’s an easier way to accomplish multi-author blogs?

Viewing 12 replies - 1 through 12 (of 12 total)
  • asechrest

    (@asechrest)

    Here’s what I’d do:

    Make your author page template, and use query_posts() with the author=” parameter.

    Remember, query_posts() should be called just before The Loop.

    asechrest

    (@asechrest)

    Also, that just lists all the author’s posts. There’s some more work to do if you want to grab the author’s profile info, and I don’t know how to do that yet since I’ll soon be diving into it. ??

    Thread Starter rubhadubh

    (@rubhadubh)

    This seems harder than it should be! I don’t really understand the distinction between Pages and Posts. I would have thought that mixing page content and filtered posts was a fairly common requirement?

    I’m looking into query_posts() and will report back. I guess once you have the author_name, or id, then grabbing other bio data should be easy enough.

    So, I have a parent page called Blogs and for each registered Author I create a child page called after their name. The child page is given a page template called blogger.php (to avoid confusion with author.php which is used by posts). In blogger.php I call query_post(‘author_name=xxxxx’) and then loop through the resulting posts? Does that roughly right? Thanks.

    asechrest

    (@asechrest)

    Check this out for Pages vs Posts. Also this to get a better understanding of how/when/why templates are called.

    Now, I think you’ve got the general idea.

    1) Create your author page
    2) Create your author page template (perhaps model it after page.php or index.php, because you’ll want to reuse a lot of the code used to loop through posts, and you’ll likely still want to call sidebars, header, etc.)
    3) Assign that template to that page in admin
    4) Use query_posts() before the loop, and use the function’s parameters to include only the posts you want
    5) Use the WordPress Loop to loop through each of the posts and display what you need/want. You could display only a title that would then link to the post, you could display the_excerpt(), or the_content().

    That’s the general idea for displaying an author’s posts.

    Thread Starter rubhadubh

    (@rubhadubh)

    Well, I have that working for a hardcoded author id, so many thanks for the query_posts() ref, but the problem remains how to get the author info from a request for a particular page where that Author is set as the Page Author – any ideas?

    Is there an array with page info once you are on a page?

    asechrest

    (@asechrest)

    I’m not sure I understand what you mean by “…set as the Page Author.” Do you just mean that said author created the page and is listed in WP admin as the author?

    I’m not sure that necessarily imparts any information to “the page.” What I mean is, far as I can find there’s no get_page_author() function.

    I imagine what we’ll be doing is grabbing author information by ID somehow, but I’m not sure.

    This is getting into territory I’m just not familiar with, though I really need to know it soon because I’m aiming for something similar.

    Maybe someone else can help us out. ??

    Thread Starter rubhadubh

    (@rubhadubh)

    Yes, in WP Admin there is a drop down labelled Page Author, where I can pick from a list of users I have assigned as Authors. It only showed up once there were Authors created.

    You would *think* that we could access this somehow on a page but I’ve spent all day looking for it – arghhh. Thanks for your help asechrest.

    There must be a function like get_page_details that returns an array of information about the current page, but I’m damned if I can find it. Anyone?

    Thread Starter rubhadubh

    (@rubhadubh)

    Good grief, I’m reduced to a series of if statements!

    The only way I can figure to do this at the moment is:

    if(is_page('author-page-1')) {$auth = 2;}
    elseif(is_page('author-page-2')) {$auth = 3;}
    query_posts("author=$auth");

    it works, but it’s not very nice! There must be a better way – anyone?

    asechrest

    (@asechrest)

    Well, it’s better than nothing! I would imagine there’s a more elegant solution, we just need someone to notice this thread. ??

    Thanks for that block of code. I’ll give it a try.

    Thread Starter rubhadubh

    (@rubhadubh)

    Ok, a better solution…

    Turns out that you can get the page id using $post->ID so I wrote a function get_page_author() and saved it in functions.php which takes the page id as a parameter and returns the post_author id from the wp_posts table, like so:

    function get_page_author($pageid){
      global $wpdb;
      $authorid = $wpdb->get_var("SELECT post_author FROM wp_posts WHERE ID = $pageid AND post_status = 'publish' AND post_type = 'page'";);
      if($authorid > 0)
        return $authorid;
      else
        return false;
    }

    in my blogger.php file I can then use that to filter the posts, like so:

    $authorid = get_page_author($post->ID);
    if($authorid){
      query_posts("author=$authorid");
    }

    Once we have the authorid we can go get other details from the database with it – I guess there are pre-made functions, but I might stick to doing it my own way! I have spent more time trying to find my way around wordpress – I could have had the whole site built and signed off by now!!

    Hope that helps you too?

    How can author information be displayed on posts on a multi-author blog?

    you should just be able to type https://yoururl.whatever/author/whatever-the-user-name-is to get an author page filled with posts from each individual author.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Setting up multi-author blog’ is closed to new replies.