WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Author archive limit number of posts problem (7 posts)

  1. relequestual
    Member
    Posted 5 years ago #

    Hi all.
    I've recently edited my theme with high success, however now I am stuck. I have had very very little luck with the WP forum recently, so I have no idea if anyone can help.

    I was re writing the archive template, which I didnt write myself in the first place. It works correctly except I cant work out how to limit the number of posts per page. It would seem the default for posts in the loop is 10, however I can't work out how to edit this either. Anyway, I successfully limited the number of posts on the home page with the query code

    <?php $next_query = new WP_Query('showposts=6'); ?>
    <?php while($next_query->have_posts()) : $next_query->the_post(); ?>

    I assumed the same would work in the archive template, however it displays posts by all authors rather than just the single author which the archive is on.
    By removing the "$next_query->" sections forms the following code.

    <?php $next_query = new WP_Query('showposts=5'); ?>
    <?php while(have_posts()) : the_post() ; ?>

    Obviously this makes the query redundant, however shows the posts from the correct author. It also lists 10 posts rather than 5, making the site load slower

    Any Ideas or help with this will be very apreciated.

    Kind Regards

    Rel

  2. @mercime
    Volunteer Moderator
    Posted 5 years ago #

    Have you checked out Codex for creating Author Templates because that's what it looks like you're trying to set up.

  3. relequestual
    Member
    Posted 5 years ago #

    Yes I have looked at that. This isn't what I'm trying to set up.
    It essentially works exactly the way I want, except the number of posts.
    The archive template file works for not only authors but for other archives to, like a yearly archive. It uses the title conditions like

    ...
    <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
              <h2 class="title">Archive for <?php the_time('Y'); ?></h2>
    <?php /* If this is a search */ } elseif (is_search()) { ?>
              <h2 class="title">Search Results</h2>
    <?php /* If this is an author archive */ } elseif (is_author()) { ?>
    	  <h2 class="title">Author Archive</h2>...

    and so on.

    I just need to be able to change the number of posts displayed per page.

  4. @mercime
    Volunteer Moderator
    Posted 5 years ago #

    Well, that's clearer now. Using showposts or limit functions would only show that number and not all the posts paginated every 5 posts. At this time, fastest way I can think of implementing post limits in archives
    1) The number set in Settings > Reading > #Blog pages show at most is applied to all multi-post views in your archives including index and search etc.
    2) Keep your Settings #Blogs and limit the number of posts in Main Page (or index or home page) with
    <?php query_posts('showposts=5'); ?>
    <?php while(have_posts()) : the_post() ; ?>
    stuff you place here like <h2>Title of Post</h2> etc
    <?php endwhile; ?>
    3) Or above not acceptable use Plugins
    - Custom Post Limits
    - Custom Query String Reloaded

  5. joebeauchamp
    Member
    Posted 5 years ago #

    What I keep running into, and am not sure if it is because I'm looking at things wrong, am old, or they really are this way, is that it should be a snap to set the limit on posts to an archive page - it isn't. I set "showposts" or some such by looking at some forum posts (why? because the freakin documentation doesn't tell me how this stuff works, so I can't go it alone), and instead of doing so, now it starts at the current top post and goes from there instead of the those for the month (in the archive).

    Doesn't it seem reasonable that I should be able to set "limit=99" for the particular thing and not have it destroy every other parameter which was obviously set by wordpress to get there? Makes no sense to me.

    Also, I see a bunch of messages here which I don't see well addressed to simply change the look of the archive. To me, an archive should be... uh, structured. Month then subject then, if you want, content. I'm surprise that this is not the default.

    So, I just tried the custom-post-limits with the result that it made no difference for my page limit on my archive page.

    Why does this have to be such a big deal and so frustrating? Seems like a simple change - the number of posts on JUST the archive page.

    So, I figure I simply must not understand the architecture of wordpress because simple things should not be so difficult, right?

    Simply, I want when someone clicks on March, they get the list of subjects to then click on if they like them -- not a barrage of content from everything in March. Well, I zapped things so that I could get everything except the limit per page. OK, simple, right? Just find the parameter and change it. Nope, just doing that and now it forgets what month I want. I'll just look at the documentation about how to control archive output... oops.. what documentation..??

    HA! I can't win... So, if I've missed something simple, I'd love to hear why I've been such an idiot trying to solve something "simple".

    thanks to all... -- Joe B.

  6. joebeauchamp
    Member
    Posted 5 years ago #

    Just wanted to change something - I found that the plugin DOES change the limit for the archive - what threw me on that is that the template still has "previous" at the end of the page - even though nothing is there.

    And, if someone reads this and would like to help in general, I found it a bear to find this posting. I gave up in wordpress and had to go to google and guess what key phrases I had. That seems odd, too. I'm used to going to my profile on other forums and seeing pointers to my postings or something similar. Also, getting email if someone replies, etc. I'm thinking that wordpress is doing all these things but in some other fashion which I have not hit upon (sort of remember getting and email for something else, I think that was wordpress, so I might be set up for that - again, I don't know) --- it is hard to believe that it is so primitive that none of these "automatic" functions are here and that it is so difficult to find my own postings. I tried all kinds of things, in posts and comments. Gave up and went to google with "wordpress archive page limit Joe" and found it almost right away (even though I had lmit instead of limit - HA!).

    Maybe I'm not alone and wordpress really could use a nicer friendlier interface? That's hard to believe since what it offers the blogger is so flexible and nice. But, obviously, I don't know..??

    thanks again.. -- Joe B.

  7. callumalden
    Member
    Posted 4 years ago #

    I've discovered the answer to this one, it does seem a function wordpress should have built in (limit posts by page). anyway:

    found via this how-to

    the snippet we're interested in is:

    <?php
    query_posts($query_string.'&posts_per_page=5');
    if (have_posts()) :
        echo "<ul>\n";
        while (have_posts()) : the_post(); ?>

    just edit posts_per_page=5 to whatever number you'd prefer to show... you will need to add something like the following to the header to make this function (see the how-to for more information):

    <?php /*
    Template Name: Author Page
    */
    get_header();
    	global $wp_query;
    	$curauth = $wp_query->get_queried_object();
    ?>

    thought i'd share that finding. using it on my new venture: leithermagazine.com do check it out once we're up and running. thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.