WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Using Multiple Loops in Index.php (3 posts)

  1. BioTecK
    Member
    Posted 4 years ago #

    Hi,

    I'm editing a theme and I'm having some problems...
    I'm using multiple loops in index.php file and on the homepage everything is exactly how I would like it to be displayed:
    1. Latest post in a box (Headline)
    2. The 8 latest posts (excluding the latest post)

    But the real problems starts when I go to page 2...
    Then I'll get only the 8 latest posts while I should get more old posts...

    I assume that that this has something to do with this:
    <?php
    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("cat=-27,-28&paged=$page&posts_per_page=8&offset=1"); ?>

    Does anyone have a clue how to get this right?

    For a copy of the index.php Click here.

  2. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

  3. BioTecK
    Member
    Posted 4 years ago #

    Thanks Alchymyth!!
    But I think I've solved it thanks to a reply which I found on this page.

    So I replaced the code below

    <?php
    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("cat=-27,-28&paged=$page&posts_per_page=8&offset=1"); ?>

    with

    <?php
    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $num_of_posts = get_option('posts_per_page');
    if ( !is_paged()){
    query_posts("paged=$page&offset=1&posts_per_page=8");
    } else {
    query_posts("paged=$page&posts_per_page=$num_of_posts"); } ?><?php $i = 1; ?>

    And it suddenly work exactly how I wanted it to!
    With this query the first page lists 8 posts (excluding the first one. All other pages will use the "default" setting as configured under: Settings -> Reading.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.