[resolved] How do I....list categories an author has wrote in on author.php (35 posts)

  1. itsbarry
    Posted 5 years ago #


    Great thread. I'd like to do something a little simpler (I hope!)

    I am modifying my author.php template.

    I want to show all posts by an author, but I want to restrict results to a single category. Always. So I'm hard-coding the category. However I have multiple authors so I have to pass the author id.

    My code:

    // housekeeping to get the author's name
    if(isset($_GET['author_name'])) :
        // NOTE: 2.0 bug requires: get_userdatabylogin(get_the_author_login());
        $curauth = get_userdatabylogin($author_name);
    else :
        $curauth = get_userdata(intval($author));
    // I just want to show blog posts in cat 6

    This doesn't work. I think my syntax could be wrong, but please let me know if I'm on the right track here.



  2. Mark / t31os
    Posted 5 years ago #

    Hi Barry,

    It may not be immediately obvious, but i've spotted your problem.. just here..


    You can't use variables inside single quotes, they get treated as literal values.

    The alternatives
    Concatate the string:

    query_posts('cat=6&author=' . $curauth);

    Switch to double quotes so you can use variables:


    First method will be faster ... but you'll not likely notice the difference. Use whichever suits you, they'll both essentially do the same..

    Hope that helps.. :)

  3. itsbarry
    Posted 5 years ago #

    Hi t31os_,

    I was hoping you'd reply!

    Actually I figured it out. I ended up going with this:


    Also I found this "in the woods" article valuable when I was putting this project together.

    thanks much!

  4. itsbarry
    Posted 5 years ago #


    My solution did not work after all.

    t310s's first approach threw an error

    So what worked for me was his second suggestion, using double quotes.

    Thanks again


  5. Gawd
    Posted 5 years ago #


    I am looking to do something along the same lines are the people here also.

    In my sidebar I have author links listed as my headings.
    When someone clicks the link to go to the author page, I'd like a listing to be displayed under there name in the sidebar with all the categories they've posted in.

    I am not sure how to get that author specific category listing.

Topic Closed

This topic has been closed to new replies.

About this Topic