WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Archive does not work anymore (displays only the two most recent posts) (7 posts)

  1. Nuuzeli
    Member
    Posted 3 months ago #

    First of all I'd like to say I'm really bad at PHP and anything I do, I do by trial and error. Therefore I always face these sort of simple problems. Anyway...

    I made a website with an archive that displays the 100 most recent posts using

    <?php global $more;
    $more = 0;
    query_posts('showposts=100');

    The website's front page, however, was limited to two posts. That I did through the WordPress settings, where I set the limit of posts on front page to two.

    This all worked great. No problems whatsoever. Well, now that I did a second website where I used the exact same code, it won't work. The second website is otherwise identical to the first, but it has two separate archives that divide the posts into two different categories. The other one shows general news and the other (football) games news. For some weird reason these archives will only show two most recent posts, just like on the front page. When I go to WordPress settings and change the limit of posts on front page to, for example, three, the archives also show three posts.

    The code I have on the second website is this (the only difference is the cat=3)

    <?php global $more;
    $more = 0;
    query_posts('cat=3', 'showposts=100');

    So my question is, why does the showposts=100 work on the first website, but not the second?

  2. Aaron
    Member
    Posted 3 months ago #

    Is it the exact same theme? Maybe the theme is controlling how many posts are being shown.

    What does it show if you remove cat=3?

  3. Nuuzeli
    Member
    Posted 3 months ago #

    Yes, this is the exact same theme I built from scratch. It's a VERY simple theme and doesn't even have search, 404, etc.

    If I remove the cat, both archives display all posts from both categories. When the cat is removed, showposts=100 works, but when I put the cat back, it stops working. So weird.

  4. Aaron
    Member
    Posted 3 months ago #

    Next I'd just check to see if the cat ID is correct and try the other one to see if it produces the same results or the correct query.

  5. Nuuzeli
    Member
    Posted 3 months ago #

    The ID's are correct. The general news archive displays posts from category 1, and the games news archive displays posts from category 3.

    For general news archive I have

    <?php query_posts('cat=1', 'showposts=100');

    And for games news archive

    <?php query_posts('cat=3', 'showposts=100');

    (P.S. Changed the original code I posted here to a more simple one, both work the same way)

    Somehow the cat messes up the showposts=100, but I don't know how. Maybe the showposts=100 works only on posts that are not categorized?

  6. alchymyth
    The Sweeper & Moderator
    Posted 3 months ago #

    syntax:

    <?php query_posts('cat=1&posts_per_page=100');

    or

    <?php query_posts( array( 'cat' => 1, 'posts_per_page' => 100 ) );

    http://codex.wordpress.org/Function_Reference/query_posts

    using query_posts() is not recommended; in your case, consider to use 'pre_get_posts'

  7. Nuuzeli
    Member
    Posted 3 months ago #

    Thank you so much alchymyth! It worked like charm! :)

Reply

You must log in to post.

About this Topic