Forums

Display Pages by Author (13 posts)

  1. iluvadama
    Member
    Posted 1 year ago #

    First of all, I'll apologize for not being a super-programmer, but I've been working for the better part of a week with WordPress tags to try to generate a list of pages posted by a user. No matter what I do, I only get a partial list or nothing at all.

    Basically, here's what I'm trying to do. I have several short-story writers who are a part of my site, and on each page for the author, I want to display the Pages (not Posts) created by the author.

    At present, I have the author's page set up by the author, where they enter their bio information, and then in the template, I want to include code that will query the DB for the author of the page (the author's individual page) and then generate a list (linked) of the other pages the author has created (those containing their stories).

    Is this feasible?

    If so, is there some kind soul here who can help me out with some code on how to do this?

    Please, though, I just ask that no one just direct me to the codex. I've been scouring it but still haven't found a way to do what I want. Me = programming challenged.

    I am grateful for any and all assistance someone (or several someones) can give.

    Thanks in advance!

    Dee

  2. Otto42
    Moderator
    Posted 1 year ago #

    So, the kicking point here is that you want to pull a bunch of Pages by those authors instead of their Posts?

    Seems to me that all you need to do is to override the post_type in your author.php template. Like this:
    query_posts($query_string.'&post_type=page');

    Put that before The Loop and you should get their pages instead of their posts.

    Or am I missing something? You are using the author template, right? Because that's kind of built in to get author posts and such.

  3. iluvadama
    Member
    Posted 1 year ago #

    Yep, Otto, that's exactly right, I want to have the pages listed for the author instead of posts, that way I can show the stories they've posted (as pages) on their profile page. I'll try your suggestion and see what happens, and post back here.

    Thank you for your reply!

    Dee

  4. iluvadama
    Member
    Posted 1 year ago #

    Okay, here's what I have...

    <ul>
    <?php query_posts('post_type=page&author='.$curauth->ID.''); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <li>
    <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
    </li>
    <?php endwhile; else: ?>
    <?php endif; ?>
    </ul>

    ... and it works except, it doesn't display the pages by the author of the page it's on, but the author who's logged in. If I do it like so...

    <ul>
    <?php query_posts('post_type=page&author=4'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <li>
    <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
    </li>
    <?php endwhile; else: ?>
    <?php endif; ?>
    </ul>

    ... giving a specific author ID, it works as I want it to. The question now is how do I pass a query so that it picks up the author ID of the current page and dynamically adds it according to which page it's on.

    Any pointers?

    Dee

  5. Otto42
    Moderator
    Posted 1 year ago #

    How about you copy and paste the exact code that I gave you in there instead? Tried that yet?

  6. iluvadama
    Member
    Posted 1 year ago #

    Yep, Otto, I tried this ....

    <ul>
    <?php query_posts($query_string.'&post_type=page');?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <li>
    <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
    </li>
    <?php endwhile; else: ?>
    <?php endif; ?>
    </ul>

    ... the results are it shows a single link, to the Author's Profile page only, and not any of the other pages they've posted.

    Suggestions?

    Dee

  7. Otto42
    Moderator
    Posted 1 year ago #

    You are doing this on the author.php template, correct? Because that code should work given that. On the author template, the author=whatever will be part of the query string, among other things.

    Do an echo of $query_string and tell me what that gives you. We need to know why your query_string is wrong.

  8. iluvadama
    Member
    Posted 1 year ago #

    I must be missing that part of the code then. I did not have an author.php and had to create one. Neither the classic or default templates with the install had an author.php either. Is there a place I can find one that would have that initial query string?

  9. Otto42
    Moderator
    Posted 1 year ago #

    No, you're misunderstanding. The query_string is automatically created by WordPress based on your input URL and your settings.

    So, did you make an author.php file for this? Or are you doing it in some other file? Or what? How you do things is important, so I need you to explain what it is, exactly, that you're doing.

    When you go to http://example.com/blog/author/otto, for example, you will normally get all of Otto's posts. To display those posts, WordPress will use the author.php file in the theme, if it's there, or index.php if it's not. So, if you don't have an author.php file, but want to customize it, then what you do is to copy index.php to author.php and then customize that file. See?

    If you do have an author.php file, then you need to:
    1. Tell me what URL you are using to get these posts.
    2. Add echo $query_string; to that author.php and tell me what it puts onto the page.

    Also, what do you mean by "the Authors Profile Page", exactly? Did you go and create a specific Page for each Author? Because that is not the correct way to do this sort of thing. Every author gets a page automatically, and that is author.php and /author/authorname as I described before. You don't create special Pages for each of them. The correct way would be to make an author.php page with special code at the top to display the information from their normal Profile page (author description, maybe their gravatar, that sort of thing). Then you only have to create one template, and every author automatically gets their own author page populated from the information already in WordPress in their profile.

  10. moshu
    Member
    Posted 1 year ago #

    It is always good to start with the Codex: Author_Templates
    (sepcial attention to the Further Readings at the bottom!)

  11. iluvadama
    Member
    Posted 1 year ago #

    Otto,

    Thank you so much for you valuable input! I went back the drawing board on the author pages. I took out the pages that I had created in a moment of idiocy, and now, I have the pages being generated via WP using the author template.

    Your input on the query string was also on the mark. I now have it displaying the author's pages, and have even added the posts as well.

    I have one other question, though. Here is the code I have now:

    <ul>
    <?php query_posts($query_string.'&post_type=page'.'&showposts=100');?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <li>
    <a href="<?php the_permalink() ?>"><?php the_title(); ?></a> <span class="tinytext">Posted: <?php the_time('m.j.y') ?></span>
    </li>
    <?php endwhile; else: ?>
    <?php endif; ?>
    </ul>

    I would like to have the page displayed in a hierarchal order, maintaining indents for sub pages of main pages. For example:

    • One-Part Story One
    • One-Part Story Two
    • Multi-Part Story
    •       MP Story Part 1
    •       MP Story Part 2
    •       MP Story Part 3
    • One-Part Story Three

    ... but I have unable to find a method of doing so. Any ideas? (I apologize for the goofiness in the appearance of the list, my nested list was altered by the editor)

    Also, I would like to have the stories displayed in alphabetical order (by title). I have attempted to add to the query string &orderby=title, like so:

    <?php query_posts($query_string.'&post_type=page'.'&showposts=100&orderby=title');?>
    and
    <?php query_posts($query_string.'&post_type=page'.'&showposts=100'.'orderby=title');?>

    ... but it is apparently ignored. Am I missing something here?

    Again, Otto, thanks so very much for your input. You rock!

    Dee

  12. Otto42
    Moderator
    Posted 1 year ago #

    You're not the only one having problems with orderby=title. There may be a bug there, somewhere.

    As far as hierarchy goes, you'll have to write some kind of custom code using the $post->post_parent. That will have the ID of the parent page in it, which will let you determine what the hierarchy is.

  13. iluvadama
    Member
    Posted 1 year ago #

    Otto,

    Glad to know it's not just me. I couldn't fathom what I was doing wrong with that code since it seemed rather straightforward.

    Thank you again for your help with this issue, Otto. You've been fantastic!

    Dee

Topic Closed

This topic has been closed to new replies.

About this Topic