• Resolved naranili

    (@naranili)


    Hi !

    I want to get the number of posts from the current LOOP (without a custom query) like the one from archiv.php or category.php.

    So this is the normal code :

    [code]

    if (have_posts()) {

    while (have_posts()) {

    the_post();

    ..... template sachen

    }

    }

    [/code]

    Now i want to get the number of posts from the loop after if have_posts()

    [code]

    if (have_posts()) {

    if (anzahl der posts == 1) {

    include ('nureinepost.php')

    } else {

    while (have_posts()) {

    the_post();

    ..... template sachen

    }

    }

    }

    [/code]

    Grüße

    Ralf

Viewing 3 replies - 1 through 3 (of 3 total)
  • do you mean: $wp_query->post_count;

    if you have your posts per page set to 10 posts, it will have the value 10 on a full page;
    if you are on the last page of a paged file, and you have 7 posts left (for instsnace) it will have the value 7.

    gruesse auch 😉

    edit: it seems that you want to run a different output file if only one post is ‘in the loop’, and the normal loop otherwise.

    You can also use $wp_query->found_posts for the total.

    Thread Starter naranili

    (@naranili)

    @alchymyth

    Hi !

    Your’re right.
    If i only have one post i wan’t to display the single.php (or the part of it to display the single post).

    Thanks for your answer.

    Regards
    Ralf

    Hatte die Post aus dem deutschen Forum kopiert, da dort anscheinend keiner eine Antwort kennt.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Current number of Posts in a LOOP’ is closed to new replies.