• Hi, Thanks for looking at this problem.

    I am trying to get an author.php template to display posts for an author from only one category. As the number of categories is dynamic I don’t think a category exclude method will work.

    Any help is much appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Please copy and paste the code from your author.php template in a pastebin and report the link back here. Thanks.

    Thread Starter Hazlitt

    (@hazlitt)

    Hi Michael,

    Thanks for replying.

    Here is a pastebin link to the code in the author.php file :

    pastbin

    Here is a link to the live site :

    Author post list

    I know how to exclude categories. The problem here is that the client will be creating and deleting categories regularly so the only way I can think of getting the author page to work properly with out my regular intervention is to some how only allow one category to be displayed. In this case the blog category.

    Thanks for your help

    How about:

    <?php
    if ( is_author() ) {
      $author = get_userdata(get_query_var('author'));
      echo 'Articles by '. $author->display_name;
      $blog_category='1';
      query_posts($query_string . '&cat=' . $blog_category);
    }
    ?>
    
    <?php /* get the relevant posts from WordPress DB */ ?>
    <?php if(have_posts()) : ?>

    Thread Starter Hazlitt

    (@hazlitt)

    Thanks Michael, that fixed it, much appreciated.

    I just want to make sure that I understand exactly what is happening here. I am guessing that $query_string is generated by the main loop and by appending the specific category number to the $query_string in the query_posts() function it queries the database for posts matching the new query.

    Have I got that right?

    Thanks again.

    Sounds good except for the “is generated by the main loop” should be “is generated based on the author selected”.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How do I get author.php to display one category?’ is closed to new replies.